From:             gynvael at coldwind dot pl
Operating system: any
PHP version:      5.4.10
Package:          SPL related
Bug Type:         Feature/Change Request
Bug description:add cast_object (to ARRAY) to SplFixedArray

Description:
------------
When comparing (using == operator) an ARRAY with SplFixedArray object one
always 
gets "false", even if arrays are exact match.
However, casting SplFixedArray to (array) beforehand does a correct (as far
as 
the == operator goes anyway) comparison.

For convenience it would be good to add a cast_object handler that does the
same 
thing that SplFixedArray::toArray function does (returns a PHP ARRAY
matching 
the SplFixedArray objects content).

Details:
The == operator uses cast_object handler when comparing ARRAY with
SplFixedArray 
object. The SplFixedArray has the default PHP cast_object handler 
(zend_std_cast_object_tostring), which fails to convert SplFixedArray to
ARRAY. 
In such case the comparison is always false (not equal).

Adding a custom cast_object handler to SplFixedArray that does the same
thing 
that ::toArray function does, would enable a developer to use $splarray ==

$array to perform a comparison, instead of using an explicit cast or
calling the 
toArray() function explicitly (see example code below).

Test script:
---------------
<?php
$arr = array(1,2,3);
$splarr = SplFixedArray::fromArray($arr);

var_dump($splarr == $arr); // Not Equal (should be)
var_dump((array)$splarr == $arr); // Equal
var_dump($splarr->toArray() == $arr); // Equal

Expected result:
----------------
bool(true)
bool(true)
bool(true)

Actual result:
--------------
bool(false)
bool(true)
bool(true)

-- 
Edit bug report at https://bugs.php.net/bug.php?id=63879&edit=1
-- 
Try a snapshot (PHP 5.4):   
https://bugs.php.net/fix.php?id=63879&r=trysnapshot54
Try a snapshot (PHP 5.3):   
https://bugs.php.net/fix.php?id=63879&r=trysnapshot53
Try a snapshot (trunk):     
https://bugs.php.net/fix.php?id=63879&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=63879&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=63879&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=63879&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=63879&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=63879&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=63879&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=63879&r=notwrong
Not enough info:            
https://bugs.php.net/fix.php?id=63879&r=notenoughinfo
Submitted twice:            
https://bugs.php.net/fix.php?id=63879&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=63879&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=63879&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=63879&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=63879&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=63879&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=63879&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=63879&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=63879&r=mysqlcfg

Reply via email to