Created
October 30, 2012 21:08
-
-
Save jehoshua02/3983070 to your computer and use it in GitHub Desktop.
Calling method and class held in array
This file contains hidden or 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 characters
| <?php | |
| class FactoryClass | |
| { | |
| public static function build() | |
| { | |
| return new ProductClass(); | |
| } | |
| } | |
| class ProductClass | |
| { | |
| } | |
| class ModelClass | |
| { | |
| protected $product; | |
| public function modelMethod($product) | |
| { | |
| $this->product = $product; | |
| } | |
| } | |
| $map = array( | |
| 'factory' => 'FactoryClass', | |
| 'callback' => 'modelMethod', | |
| ); | |
| $model = new ModelClass(); | |
| $model->$map['callback']($map['factory']::build()); | |
| var_dump($model); |
Author
Author
$ php --version
PHP 5.3.10-1ubuntu3.2 with Suhosin-Patch (cli) (built: Jun 13 2012 17:19:58)
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I did not think that
$model->$map['callback']($map['factory']::build());would work at all, but it did!