MemoryRefresh!

Features / Late static binding   Late static binding



Questions Answers 0%

Pages   0 from 91
Questions   0 from 142

Reset


As of PHP 5.3.0, PHP implements a feature called late static binding which can be used to reference the called class in the context of static inheritance. LSB tries to solve that limitation by introducing a keyword that references the class that was initially called at runtime. Static methods or properties can be access only as part of a class itself.
<?php class Car { public static $name = "Car"; public static function getName($self=false) { if ($self === true) return self::$name; return static::$name; // --- Look Here --- // } } class Toyota extends Car { public static $name = "Toyota"; } $car = new Toyota(); echo Car::$name; // Car echo $car->name; // Notice: Undefined property // static can't be access as part of class instantiation echo $car->getName(); // Toyota echo $car->getName(true); // Car

Related Pages

Introduction
Autoload
Class reflection
Magic methods
Late static binding
Type hinting
Exceptions


0% 100%
 
 
0 pages 91 pages
1) Which is correct?








As of PHP 5.3.0, PHP implements a feature called late static binding which can be used to reference the called class in the context of static inheritance. LSB tries to solve that limitation by introducing a keyword that references the class that was initially called at runtime. Static methods or properties can be access only as part of a class itself.
<?php class Car { public static $name = "Car"; public static function getName($self=false) { if ($self === true) return self::$name; return static::$name; // --- Look Here --- // } } class Toyota extends Car { public static $name = "Toyota"; } $car = new Toyota(); echo Car::$name; // Car echo $car->name; // Notice: Undefined property // static can't be access as part of class instantiation echo $car->getName(); // Toyota echo $car->getName(true); // Car

References









Programming

Php
   
Regex
   
MySQL
   
Css
   
jQuery
   
Git
   


References