The Developer Day | Staying Curious

Apr/08

16

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:

my_sort_function(&$array);

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 devolux.org