PHPDoc type hinting for array of objects?

In the PhpStorm IDE from JetBrains, you can use /** @var SomeObj[] */, e.g.: /** * @return SomeObj[] */ function getSomeObjects() {…} The phpdoc documentation recommends this method: specified containing a single type, the Type definition informs the reader of the type of each array element. Only one Type is then expected as element for … Read more

How to run single test method with phpunit?

The following command runs the test on a single method: phpunit –filter testSaveAndDrop EscalationGroupTest escalation/EscalationGroupTest.php phpunit –filter methodName ClassName path/to/file.php For newer versions of phpunit, it is just: phpunit –filter methodName path/to/file.php

Laravel requires the Mcrypt PHP extension

Do you have MAMP installed? Use which php in the terminal to see which version of PHP you are using. If it’s not the PHP version from MAMP, you should edit or add .bash_profile in the user’s home directory, that is : cd ~ In .bash_profile, add following line: export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH Edited: First you should … Read more

How to convert an array to object in PHP?

In the simplest case, it’s probably sufficient to “cast” the array as an object: $object = (object) $array; Another option would be to instantiate a standard class as a variable, and loop through your array while re-assigning the values: $object = new stdClass(); foreach ($array as $key => $value) { $object->$key = $value; } As … Read more