Accessing a Property from Within a Method : Class Property « Class « PHP






Accessing a Property from Within a Method

 
<?php
class Item {
  var $name = "item";

  function getName () {
    return $this->name;
  }
 }

 $item = new Item ();
 $item->name = "widget 5442";
 print $item->getName ();
?>
  
  








Related examples in the same category

1.Assign default property value
2.Changing the Value of a Property from Within a Method
3.Define boolean Class properties
4.Adding Properties
5.Adding the $age variable to Cat
6.Changing the Value of a Property from Within a Method
7.Class including a complete collection of get and set methods.
8.Controlling Access to Class Members
9.Define a setter and getter