________________________________
Printable View
________________________________
scope. var is local scope. public is, well, public.
-tg
i have never seen 'var' used in PHP. Can you show me where you have seen it?
i know var is used in Javascript to define a string
MyBB database class(MySQL). and...
@dclamp - well, how else do you define a local variable in PHP? That's the way Iv'e always done it....
-tg
Because PHP is typeless, all variables are defined when they are first used; variables are given the type of the value they are assigned. Therefore in order to declare an integer you would use:
There are instances where it is useful to declare the presence of a variable which may or may not be used. The var keyword is used to declare class variables only and was introduced in PHP 4.PHP Code:$i = 1;
Before a declared class variable is used it is assigned a null value. In PHP 5 var was superseded by the class visibility modifiers (public / private and protected). var can still be used in PHP 5 but it is generally considered better practice to use either public, private or protected. Var will likely also be removed in PHP 6.PHP Code:class Foo {
var $myProperty;
function Foo()
{
$this->myProperty = 'hello';
}
}
The visibility modifiers can also be applied to class methods in PHP 5 too. PHP is becoming more of a typed language since the introduction of the PHP 5 object model which also introduced type hinting to force function arguments to be of a particular object type.PHP Code:class Foo {
private $myProperty;
public function __construct()
{
$this->myProperty = 'hello';
}
}