php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #51922 Controlled typecasting for objects that implement the "Countable" interface
Submitted: 2010-05-26 15:06 UTC Modified: 2010-08-07 01:55 UTC
From: korchasa at gmail dot com Assigned:
Status: Not a bug Package: SPL related
PHP Version: 5.3.2 OS: Any
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: korchasa at gmail dot com
New email:
PHP Version: OS:

 

 [2010-05-26 15:06 UTC] korchasa at gmail dot com
Description:
------------
Now we have no ways to controll type casting of Countable-objects to boolean 
type. We would like to work with the SPL-derivatives, as well as with the built-
in types.

Test script:
---------------
<?php
class myCountable implements Countable
{
  function count()
  {
    return 0;
  }
}

var_dump((boolean) array());
var_dump((boolean) new myCountable());


Expected result:
----------------
bool(false)
bool(false)


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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-08-07 01:55 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2010-08-07 01:55 UTC] johannes@php.net
Even with count() returning null an object often is a "true" value and we decided not to add other casting functions (other than __toString())
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 20:01:29 2024 UTC