|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2012-05-25 14:24 UTC] laruence@php.net
-Status: Open
+Status: Not a bug
[2012-05-25 14:24 UTC] laruence@php.net
[2014-12-27 10:17 UTC] evought at pobox dot com
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 16:00:02 2025 UTC |
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)