RE: [PHP] VAR and variables
| From: | Steve Edberg | Date: | Mon, 29 Jan 2001 11:38:17 +0000 |
| Subject: | RE: [PHP] VAR and variables | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-37100@lists.php.net to get a copy of this message | ||
At 10:50 AM +0000 1/29/01, Tim Ward wrote:
-----Original Message-----Yes --- I was referring to the use of the keyword 'var' here (as opposed to nothing, or some _other_ construct), which I think was the original question.From: Steve Edberg [mailto:sbedberg@ucdavis.edu] Sent: 25 January 2001 22:02 To: Matt; php-general@lists.php.net Subject: Re: [PHP] VAR and variables At 3:00 PM -0600 1/25/01, Matt wrote:I have a question that may seem kind of silly, but I'm curious... When using PHP why would one use "var" to define a variable as opposed to just regularly creating it?Because that's the way it is ;). The var is part of the syntax of a class definition; it isn't used anywhere else. I don't know the actual deep reason for having it, as far as the parser is concerned, but it does make it clear - at least to me - what the class variables are.class definitions are the fundamental building blocks of object orientated programming. They define an object type which your object is an example of. The defined variables should be regarded as properties of the class rather than variables in the usual sense. If you're going to be strict about it you should not even refer to them directly outside the class definition but use methods to access and change them.
According to the docs, you can still use a _constant_ initializer in PHP4 (I use them in 4.0.4), just not a variable one. From http://www.php.net/manual/en/language.oop.php: Note: In PHP 4, only constant initializers for var variables are allowed. Use constructors for non-constant initializers. Of course, this might not be the official OOP usage, but this is PHP's way (I'd call it Pseudo-OOP, but the acronym for that isn't all that pleasant ;) - steve -- +--- "They've got a cherry pie there, that'll kill ya" ------------------+ | Steve Edberg University of California, Davis | | sbedberg@ucdavis.edu Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-------------------------------------- FBI Special Agent Dale Cooper ---+You can also initialize the variable here, too: var $a = 5;not any more you can't ... use the constructor