Numeric and integer keys

<?php
$a
= 1;
$b ->$a = 'foo';
var_export((array)$b);
var_export(array(1 => 'foo'));
?>

Results:
array (
  '1' => 'foo',
)array (
  1 => 'foo',
)

Observe the '1'. The array element after casting can not be reached via the [] operator. (And no, "'1'" wont do the trick.)

Comments

It's casting the 1 to a

It's casting the 1 to a string because class variables cannot start with numbers, just like functions. Doing $b->$a caused $a to be converted to a string. However, that is very WTF about not being able to retrieve the array element using []. At least you can still get it if $b is still an object and you can do var_export($b->$a).

That's actually pretty nifty

That's actually pretty nifty -- I did not know that casting an object to an array causes numeric string keys to fail to convert. That should probably be a filed as bug.

This site consists of an

This site consists of an ample number of posts but the posts are quite sensible for all to view.
Carefully read all the contents its having very important information.

Good post

Hi, I must say that you have made some good points in the post. I performed searches on the topic and found most people will agree with your blog. Thanks for sharing this information.
how to remove skin tags

You have managed to find a

You have managed to find a bug which could have caused problem,thanks a lot..onketing india

PHP is a very difficult

PHP is a very difficult language and you seem to have mastered it,because of why you find out the bugs in it..how to remove a mole

really nice site to visit .

really nice site to visit . nice piece of information posted on this site. keep posting. Thankshome remedies for mole removal

It is great to have the

It is great to have the opportunity to read a good quality article with useful information on topics that plenty are interested on
642-432 exam
PW0-200 exam
350-040 exam
70-444 exam
650-393 exam
VCP-511 exam
642-731 exam
BR0-001 exam

It is so lucky to read your

It is so lucky to read your blog,it is full of useful message.I wish we both can do better in the future.It great honor if you can visit our website,and give us some suggestion.
EC0-350 dumps
70-284 dumps
642-504 dumps
642-845 dumps
642-873 dumps
312-49 dumps
642-456 dumps
642-426 dumps

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options