Created
April 12, 2013 08:46
-
-
Save rupertj/5370574 to your computer and use it in GitHub Desktop.
PHP isset tests
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 | |
error_reporting(E_ALL | E_STRICT); | |
ini_set('display_errors', '1'); | |
define('LANGUAGE_NONE', 'und'); | |
echo "<pre>"; | |
// Test an object with an array as a property. | |
if (isset($node->field[LANGUAGE_NONE][0]['value'])) { | |
echo "Object set\n"; | |
} | |
else { | |
echo "Object not set\n"; | |
} | |
$node = new stdClass(); | |
$node->field = array(); | |
$node->field[LANGUAGE_NONE][0]['value'] = 'foo'; | |
if (isset($node->field[LANGUAGE_NONE][0]['value'])) { | |
echo "Object set\n"; | |
} | |
else { | |
echo "Object not set\n"; | |
} | |
// Test previous object in an array. | |
if (isset($form['node']->field[LANGUAGE_NONE][0]['value'])) { | |
echo "Object in array set\n"; | |
} | |
else { | |
echo "Object in array not set\n"; | |
} | |
$form['node'] = $node; | |
if (isset($form['node']->field[LANGUAGE_NONE][0]['value'])) { | |
echo "Object in array set\n"; | |
} | |
else { | |
echo "Object in array not set\n"; | |
} | |
echo "</pre>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment