|
Posted by Schraalhans Keukenmeester on 07/13/07 10:51
At Fri, 13 Jul 2007 10:14:13 +0000, MichaelD let h(is|er) monkeys type:
> Just read a book on OOPHP and started playing around with PHP's OOP.
> Most of it's working just fine, but I cant seem to figure out how to
> access static attributes - here's my code:
>
> class testing implements Iterator
> {
> protected static $connection = false;
> ...
>
> public static function setConnection($connection)
> {
> if(!testing::connection)
> $this->connection = $connection;
> }
>
> public function __construct($query)
> {
> if(!testing::connection)
> echo 'Connection not set.';
> }
> ...
> }
>
> So here's my problem(s): first off, I get a Fatal error: Undefined
> class constant 'connection' at the line 'if(!testing::connection)' in
> the constructor. Using $this->connection doesn't work (and it
> wouldn't really make sense if it did) using self::connection causes
> the same error as testing::connection (which also makes sense) but I
> cant figure out how to refrence the attribute.
>
> That said, see the static function above? That gets by another class
> called before the constructor, and it works fine. Previously I used
> testing::connection = $connection; but that threw an error and told me
> to use $this-> which doesn't make any sense at all, since there isn't
> a $this object to refrence.
>
> Can someone please explain both what I'm doing wrong and how to
> properly work with static attributes?
Try using testing::$connection instead of testing::connection.
HTH
--
Schraalhans Keukenmeester - schraalhans@the.Spamtrapexample.nl
[Remove the lowercase part of Spamtrap to send me a message]
"strcmp('apples','oranges') < 0"
Navigation:
[Reply to this message]
|