note 115806 deleted from function.str-split by crell
| From: | crell@php.net | Date: | Wed, 29 Jun 2022 18:29:28 +0000 |
| Subject: | note 115806 deleted from function.str-split by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218681@lists.php.net to get a copy of this message | ||
Note Submitter: kunal dot b at indiaproperty dot com
----
Note that in atleast in PHP 5.5.9 (Zend Engine v2.5.0), str_split with an integer value as an
argument may return unpredictable results.
If your number contains leading 0's, the result array is unprdictable as it may contain any
number of digits from the argument or (mostly) just a 0.
Here are a list of possible values that might be returned:
-Interger
<?php
print_r(str_split(0080450)); // does not work
print_r(str_split(strval(0080450))); // neither this
/*
* Outputs:
* Array
* (
* [0] => 0
* )
*/
?>
BUT
<?php
print_r(str_split(80450)); // works fine
print_r(str_split(strval(80450))); // so does this
/*
* Outputs:
* (
* [0] => 8
* [1] => 0
* [2] => 4
* [3] => 5
* [4] => 0
* )
*/
?>
Floating point numbers have their leading and trailing 0s cut off:
<?php
print_r(str_split(0080450.0010)); // works but.. print_r(str_split(strval(0080450.0010))); //
same here..
/*
Outputs:
* Array
* (
* [0] => 8
* [1] => 0
* [2] => 4
* [3] => 5
* [4] => 0
* [5] => .
* [6] => 0
* [7] => 0
* [8] => 1
* )
*/
?>
I'm not sure if this can be considered a bug, since this is due to how type conversion and
casting works, so i just posted it here.
I've notced that this is how strval() works. Can anyone shed light into this?..