php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47697 Count function returning 1 for an object
Submitted: 2009-03-17 22:13 UTC Modified: 2009-03-17 22:34 UTC
From: justinvex at yahoo dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.2.9 OS: Linux
Private report: No CVE-ID: None
 [2009-03-17 22:13 UTC] justinvex at yahoo dot com
Description:
------------
Hi this is returning 1 when I think it should return 3 for the number of 
properties in the object. Maybe I am doing this wrong. Thanks...





Reproduce code:
---------------
$i = new StdClass();
$i->propOne = "Prop 1";
$i->propTwo = "Prop 2";
$i->propThree = "Prop 3";

print count($i);

Expected result:
----------------
prints 3

Actual result:
--------------
prints 1

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-17 22:34 UTC] felipe@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Says the documentation:

"If var is not an array or an object with implemented Countable interface, 1 will be returned [...]"
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 18 20:00:03 2025 UTC