Edit report at https://bugs.php.net/bug.php?id=62155&edit=1
ID: 62155
User updated by: gordon dot mcvey at ntlworld dot com
Reported by: gordon dot mcvey at ntlworld dot com
Summary: empty () returns false for Countable objects with a
count of 0
Status: Open
Type: Bug
Package: SPL related
PHP Version: 5.3.13
Block user comment: N
Private report: N
New Comment:
m
Previous Comments:
------------------------------------------------------------------------
[2012-05-25 10:16:13] gordon dot mcvey at ntlworld dot com
Description:
------------
If you call empty() on an array with 0 elements, then it will return true.
However, if you call empty() on a Countable object with a count of 0, it
returns
false.
This could catch out people who are implementing objects with Countable as
array
stand-ins.
Test script:
---------------
<?php
class Test implements Countable
{
public $count = 0;
public function count ()
{
return intval (abs ($this -> count));
}
}
$test = new Test ();
var_dump (empty ($test));
var_dump (count ($test));
$test -> count = 10;
var_dump (empty ($test));
var_dump (count ($test));
Expected result:
----------------
bool(true)
int(0)
bool(false)
int(10)
Actual result:
--------------
bool(false)
int(0)
bool(false)
int(10)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62155&edit=1