You are here: Static Attributes « All PHP « IT news, forums, messages
Static Attributes

Posted by MichaelD on 07/13/07 10:14

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?

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация