Created
March 29, 2011 11:55
-
-
Save rdohms/892220 to your computer and use it in GitHub Desktop.
Solution to always checking the array elements to avoid PHP notices
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 | |
//Original code | |
$this->setProperty( $data['property'] ); | |
//How it has to be done because array may not contain that value (its optional) | |
$this->setProperty( isset($data['property'])? $data['property'] : null ); | |
/* | |
* Question is: Is there a cleaner way of doing this, if so, how? | |
* | |
* Second question, is: would the code below (create a native php function) make sense as a good solution? | |
*/ | |
$this->setProperty( array_read('property', $data ); | |
// In this case the C code behind this would check for presence of the key and return null if not present | |
// Another solution is to create a SPL function in PHP format to do this | |
//Thanks |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@rdohms agreed