Use public properties directly : public « Class « PHP






Use public properties directly


<?php
    class Employee {
        public $title       = "name";
        public $mainName    = "main name";
        public $firstName   = "first name";
    }

$product1 = new Employee();
$product1->title = "title";
$product1->mainName  = "A";
$product1->firstName = "B";

print "author: {$product1->firstName} " . "{$product1->mainName}\n";
?>

           
       








Related examples in the same category

1.Public fields
2.public method
3.A Class with Public Properties
4.Using Class Visibility Operators