NYCPHP Meetup

NYPHP.org

[nycphp-talk] Let's talk about the 'var' keyword

Daniel Convissor danielc at analysisandsolutions.com
Fri Mar 12 10:18:18 EST 2004


On Fri, Mar 12, 2004 at 10:13:54AM -0500, Chris Bielanski wrote:

> it never occured to me before but I note that it *appears* that the 'var'
> keyword is only allowed in classes in PHP 4. AFAIK, using it in a PHP4
> function is verboten.

Correct.  It's used in Object Oriented Programming.  Var defines 
properties' default values.  Note that they need to be defined outside of 
methods (nb: in classes, functions are called methods).   Example:

class foo {
    var $x = 'y';
    function bar() {
    }
}

var is deprecated in PHP 5, raising a new E_STRICT warning.  Instead of 
using var, use public, private, protected, etc.

--Dan

-- 
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
            data intensive web and database programming
                http://www.AnalysisAndSolutions.com/
 4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409



More information about the talk mailing list