fcab Posted February 15, 2004 Posted February 15, 2004 I am not sure how to use the return statement for the code below. It works fine with echo. I do not think echo should be use in the code below. I am new to php and a little help wold be great. Thanks, Chris class myclass { var $variable = 'test'; function myclass($TEST = 'It') { $TEST .= ' Works'; // Can you use echo or print in the statement below. If not how do you use the return statement to out put "It Works" /////////////// echo $TEST;/// ////////////// } } new myclass();
♥ecartz Posted February 17, 2004 Posted February 17, 2004 echo is fine if you always want to output the results of the function at object creation. Another way to get the same effect is to assign the value to a class variable and create a return function for the class variable: class myclass { var $variable = 'test'; function myclass($TEST = 'It') { $TEST .= ' Works'; $this->variable = $TEST; return $this; } function get_variable() { return $this->variable; } } $my_obj = new myclass(); echo $my_obj->get_variable(); This way, you could create the object at one place; work on it elsewhere; then finally display it. Hth, Matt Always back up before making changes.
fcab Posted February 19, 2004 Author Posted February 19, 2004 :D :D :DThanks Matt that helps a lot. :D :D :D
Recommended Posts
Archived
This topic is now archived and is closed to further replies.