Skip to content

Instantly share code, notes, and snippets.

@rupertj
Created April 12, 2013 08:46
Show Gist options
  • Save rupertj/5370574 to your computer and use it in GitHub Desktop.
Save rupertj/5370574 to your computer and use it in GitHub Desktop.
PHP isset tests
<?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