Created
July 24, 2011 14:28
Revisions
-
davidino revised this gist
Jul 24, 2011 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,5 @@ php -S localhost:8124 <?php $a = array( -
davidino created this gist
Jul 24, 2011 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,104 @@ <?php $a = array( 'logger' => function () {echo 'loggin really serious stuff';} ); echo $a['logger']() . "\n"; class Car { protected $manufacturer = NULL; public function getSerialId() { return rand(0, 999); } public function allowsDriversOver() { return 18; } public function isA($manufacturer) { if ($this->manufacturer == $manufacturer) { return true; } } } class StandardCar extends Car { } class MiniCar extends Car { public function allowsDriversOver() { return 16; } } class BmwCar extends StandardCar { use BmwManufactured; } class BmwMiniCar extends MiniCar { use BmwManufactured; } trait BmwManufactured { protected $manufacturer = 'bmw'; public function getSerialId() { return parent::getSerialId() . "-bmw"; } public function allowsDriversOver() { return 21; } } $bmwCar = new BmwCar(); $bmwMiniCar = new BmwMiniCar(); echo 'Macchina BMW: ' . $bmwCar->allowsDriversOver() . ", " . $bmwCar->getSerialId() . "\n"; echo 'Mini BMW: ' . $bmwMiniCar->allowsDriversOver() . ", " . $bmwMiniCar->getSerialId() . "\n"; $car = new car(); echo 'Macchina: ' . $car->allowsDriversOver() . ", " . $car->getSerialId() . "\n"; $miniCar = new Minicar(); echo 'Macchina mini: ' . $miniCar->allowsDriversOver() . ", " . $miniCar->getSerialId() . "\n"; if ($bmwCar->isA('bmw')) { echo "Ho una BMW!\n"; } class ClosureContainer { protected $value = 13; public function getValue() { $a = function () { return $this->value; }; return $a(); } } $cc = new ClosureContainer(); echo $cc->getValue() . "\n"; echo "\n";