php - Passing parameters from an outside file to a class -
i need have 2 files. let's call file controlling second one: main.php , let's call secondary file, 1 code: second.php
in second.php have:
<?php class tags{ var $theuser; var $thebarname; var $theplace; var $thetime; var $themail; function __construct($theuser,$thebarname,$theplace, $thetime, $themail){ $this->theuser=$theuser; $this->thebarname=$thebarname; $this->theplace=$theplace; $this->thetime=$thetime; $this->themail=$themail; } function give_tags_theuser(){ return $this->theuser; } function give_tags_thebarname(){ return $this->thebarname; } function give_tags_theplace(){ return $this->theplace; } function give_tags_thetime(){ return $this->thetime; } function give_tags_themail(){ return $this->themail; } } $tags = new tags("john", "starbucks", "ny", "4:30", "example@example.com"); $user= $tags->give_tags_theuser(); $barname = $tags->give_tags_thebarname(); $place = $tags->give_tags_theplace(); $time = $tags->give_tags_thetime(); $email = $tags->give_tags_themail(); // data before send email using phpmailer, that's story ?>
in main.php need pass variables class. meaning delete:
$tags = new tags("john", "starbucks", "ny", "4:30", "example@example.com");
from second.php , passing data main.php
what have change in second.php , how main.php in order so?
if did not explain myself, please tell me so, i'm still student , i'm still messing vocabulary.
thanks lot
if using classes shouldn't doing operations on classe inside files define classes.
for example given situation should define tags
class inside file called tags.php
make main.php
file runner of application, in file do:
require_once 'tags.php' $tags = new tags("john", "starbucks", "ny", "4:30", "example@example.com"); $user= $tags->give_tags_theuser(); $barname = $tags->give_tags_thebarname(); $place = $tags->give_tags_theplace(); $time = $tags->give_tags_thetime(); $email = $tags->give_tags_themail();
this better writing code runs application in multiple files.
Comments
Post a Comment