How does "var" work in PHP5?
Moderator: General Moderators
How does "var" work in PHP5?
I noticed that phpDocumentor requires class variables to be preceeded by the keyword var in order for them to show up in the generated documentation. I initially had my variables defined as "private $somename" and switched them to "var private $somename", which phpDocumentor liked but PHP gave an error on. "private var $somename" didn't seem to work either. I can drop the "private" and I believe it will work, but I don't think I should have to. What if I wanted to specificy a protected variable, for instance. What's the correct way for both PHP and PhpDocumentor to be happy? What am I missing?
Re: How does "var" work in PHP5?
var is php4 specific. php5 will not produce fatal error out of it but think of it as public modifier....will just issue strict warning that this is depricated and public/private/protected should be used only. as of phpdocumentor..by default it just ignores private and protected properties. That's the whole idea of encapsulation OO model. When you see a documentation about an API (one that phpdoc produces) you're intersted in things that are public (methods/properties)..things that you could interract with..and not be bothered with internals of the API. I guess phpdoc just looks by default for var or public in order to process... It accepts var private just because it knows you can't leave it this way anyhow..php will produce parse error. If not mistaken there is flag that you can pass so private properties/methods are also included..but in my opinion this is just wrong.
As for var private / var public this is just fatal error... modifier is just var (only in php4 in php5 public should be used), public, protected, private....... you can read on those on php.net/oop5
As for var private / var public this is just fatal error... modifier is just var (only in php4 in php5 public should be used), public, protected, private....... you can read on those on php.net/oop5