Created
January 25, 2013 13:21
-
-
Save idev247/4634377 to your computer and use it in GitHub Desktop.
Trick to get options from default values.
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 TestStuff { | |
private $defaults = array( | |
'color' => '#00ff00' | |
); | |
public function doIt() { | |
return $this->__request(array('color' => '#ff0000')); | |
} | |
public function getIt() { | |
return $this->__request(); | |
} | |
private function __request(array $options = array()) { | |
$options = array_filter(array_intersect_key(array_merge($this->defaults, $options), $this->defaults)); | |
echo $options; // from doIt it would echo '#ff0000' but from getIt it would be '#00ff00' | |
} | |
} |
xeoncross
commented
Jan 26, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment