Re: learning to right objects
| From: | Blake Schroeder | Date: | Wed, 11 Aug 2004 21:47:06 +0000 |
| Subject: | Re: learning to right objects | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-193511@lists.php.net to get a copy of this message | ||
Justin
Thank you now I have a working example to go from.
Justin Patrin wrote:
On Wed, 11 Aug 2004 16:35:33 -0500, Blake Schroeder <blake@lhwd.net> wrote:-- +-----------------+-----------------+----------------+ | Blake Schroeder | Owner/Developer | lhwd.net | +--(http://www.lhwd.net)------------+--/3174026352\--+I am trying to change some of my functions in to classes and objects. I have been checking out the php.net and google and still not grasping the concept. here is my example all I am trying to do is print 2 numbers to the browser that are randomly generated from dieRolls. Thanks in advance -Blake class dieRolls{You're storing this value in a local var, not an object property. Try: $this->num = rand(1, $die);function dieRolls($die){ $num = rand(1, $die);This does nothing as $this->num is not set (see above) and you're not *doing* anything with it.$this->num;I don't know what you think these two lines are doing. You never set bar1 or bar2, so you'r enot going to get anything.}} $num1 = new dieRolls("6"); $num2 = new dieRolls("8"); $bar1 = $num1->bar1; $bar2 = $num2->bar2;echo"Hi<br>\n"; echo"$bar1<br>\n"; echo"$bar2<br>\n";I would suggest using this (after fixing the first problem I pointed out): echo $num1->num."<br/>\n"; echo $num2->num."<br/>\n";