PHP Posts

DB::DBAL DB::DBAL is a lightweight Database Abstraction Layer that is designed to allow for multiple database types and connections simultaneously. DB::DBAL provides ease of use of use through query chaining,...

Read more

Form Builder To be perfectly honest, this is a class I built awhile ago (back in November of 2010), so going from memory here. But basically, Form Builder allows you to setup a databased/ emailed form quickly and...

Read more

Weekly PHP Test What is the output of the following code? [php]echo (string) 042;[/php] ... ... ... ... ... ... ... ... ... ANSWER: [crayon]34[/crayon] Because the number starts...

Read more

Weekly PHP Test What does the following code echo out: [php] if('ORANGE' > 'apple') { echo 'orange'; } else { echo 'apple'; } [/php] ... ... ... ... ... ... ANSWER: [crayon]apple[/crayon] The...

Read more

PHP 5.4 – First Glances Updated February 10, 2012 PHP 5.4 is just around the corner, and with it several new features and enhancements.  Here are just a few of the features I've had the chance to play with that may be useful. Binary...

Read more

  • Prev
  • Next

Weekly PHP Test

Category : Weekly Test

What does the following code produce in PHP 5.0+

PHP
1
2
3
4
5
6
$var = (object) array('0'=>'hello world');
if(isset($var[0])) {
die('Is Set');
}
die('Not Set');

.

.

.

.

.

.

ANSWER:

Fatal Error!

In PHP trying to access an object property using array syntax throws a fatal error, however, trying to access an array key/value using object syntax will return false on isset!

Just remember anytime you have a variable that can be either an object or an array to check using the appropriate functions (is_object, is_array) before trying to access its properties.
.

PHP Manual:
http://php.net/manual/en/function.isset.php

Facebook Twitter Linkedin Digg Reddit Stumbleupon Tumblr Posterous Email Snailmail
Share

Post a comment