At 10:50 AM +0000 1/29/01, Tim Ward wrote:
>  > -----Original Message-----
>>  From: Steve Edberg [mailto:[EMAIL PROTECTED]]
>>  Sent: 25 January 2001 22:02
>>  To: Matt; [EMAIL PROTECTED]
>>  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.


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.



>  >
>>  You can also initialize the variable here, too:
>>
>>      var $a = 5;
>>
>
>not any more you can't ... use the constructor


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 |
| [EMAIL PROTECTED]                               Computer Consultant |
| http://aesric.ucdavis.edu/                  http://pgfsun.ucdavis.edu/ |
+-------------------------------------- FBI Special Agent Dale Cooper ---+

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to