Re: Basics of OOP
| From: | Nathan Rixham | Date: | Tue, 09 Sep 2008 19:23:09 +0000 |
| Subject: | Re: Basics of OOP | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-279748@lists.php.net to get a copy of this message | ||
Ben Stones wrote:
Hi, The following bit of code doesn't output anything: <?phpit's the lack of a methodCall() $class->outputText; <<don't work $class->outputText(); <<will work while you're there why not learn the php5 way? <?php class output { private $text; public function outputText( $text='default text' ) {class output { var $text; function outputText() { $this->text = "Hello World"; echo $this->text; } }$class = new output(); $class->outputText;?> As well as the following code: <?phpclass output { var $text=5; function outputText() { echo $this->text; } }$class = new output(); $class->outputText;?> Am I doing anything wrong? By the way, the preceding code is just so I understand OOP which finally I've grasped, but am I doing anything wrong as both codes don't output anything?
$this->text = $text;
return $this->text;
}
}
$class = new output;
$class->outputText();
?>
just a suggestion save you double learning! good choice on the OO though
nathan