Use var
to create a property:
<?php
class MyClass {
var $name = "John";
}
$obj = new MyClass();
echo $obj->name;
?>
Try it Yourself »
The var
keyword creates a property in a class. Since PHP 5, it is equivalent to the public
keyword.
Note: The var
keyword is only used for compatibility reasons. Since PHP 5, the keywords private
, protected
and public
should be used instead.
The public
keyword.
The protected
keyword
The private
keyword
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!