Example
Use var to create a property:
html
<?php
class MyClass {
var $name = "John";
}
$obj = new MyClass();
echo $obj->name;
?>
Definition and Usage
The var keyword creates a property in a class. Since PHP 5, it is equivalent to the public keyword.
Note: The
varkeyword is only used for compatibility reasons. Since PHP 5, the keywordsprivate,protectedandpublicshould be used instead.
Related Pages
The public keyword.
The protected keyword
The private keyword