PHP var Keyword

❮ PHP Keywords

Example

Use var to create a property:

<?php
class MyClass {
  var $name = "John";
}

$obj = new MyClass();
echo $obj->name;
?>
Try it Yourself »

Definition and Usage

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.


Related Pages

The public keyword.

The protected keyword

The private keyword


❮ PHP Keywords
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.