The Developer Day | Staying Curious



Exotic PHP data type tips and tricks

What do you think the output of this code snippet would be:

$array = array (0.1 => 'a', 0.2 => 'b');
echo count ($array);

It’s 1! In PHP array keys can only be made from integers and strings. Strangely enough it accepts floats too and casts them to integers!

While reviewing old code you might find stuf like:


Note that the $array is passed by reference. Yet again it turns out this kind of technique is deprecated and one should redeclare the function to accept the $array by reference. Common in PHP itself. Sadly I didn’t get a helpful warning that this type of technique is deprecated.

RSS Feed

No comments yet.

Leave a comment!



Find it!

Theme Design by