Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

Keyword var

The historical var property declaration gives the property public visibility.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

var string $label = "open";

The historical var property declaration gives the property public visibility. It still works with a type declaration in PHP 8.4. It belongs in a class body and declares a property on each instance. Local variables in a function do not use this keyword.

class Badge {var string $label="open";}
$a=new Badge(); $b=new Badge(); $a->label="closed"; echo json_encode([$a->label,$b->label]);
["closed","open"]

Examples

<?php
class Badge {var string $label="open";}
$a=new Badge(); $b=new Badge(); $a->label="closed"; echo json_encode([$a->label,$b->label]);

Result

["closed","open"]

Sources