Created
December 25, 2013 14:20
-
-
Save Danack/8123572 to your computer and use it in GitHub Desktop.
Example of object returned from factory not being return type hinted.
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 characters
{ | |
"methodCalls": [ | |
{ | |
"class": "Maker", | |
"method": "make", | |
"position": 0 | |
} | |
], | |
"functionCalls": [ | |
{ | |
"function": "\\verify", | |
"position": 0 | |
} | |
] | |
} |
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 characters
<?php | |
class Maker { | |
function make($className) { | |
return new $className; | |
} | |
} | |
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 characters
<?php | |
class MakerFactory { | |
/** | |
* @return Maker | |
*/ | |
function create() { | |
return new Maker(); | |
} | |
} | |
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 characters
<?php | |
function shamoan($className) { | |
return new $className(); | |
} | |
class TestClass { | |
function foo() { | |
} | |
} | |
$maker = new \Intahwebz\Maker(); | |
$makerFactory = new \Intahwebz\MakerFactory(); | |
//Commenting out this line makes it work. | |
$maker = $makerFactory->create(); | |
$object = $maker->make("TestClass"); | |
$object-> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment