ID:               50599
 Updated by:       [email protected]
 Reported By:      jmcentire at gmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Feature/Change Request
 Operating System: Debian
 PHP Version:      5.3.1
 New Comment:

gettype should really give the type, your class will always behave
differently from an integer (just think about by value and by ref)


Previous Comments:
------------------------------------------------------------------------

[2009-12-29 00:35:42] jmcentire at gmail dot com

Description:
------------
I'm modeling my data as objects and would like it to be as transparent

as possible.  As such, gettype($myObj) should return a type value other

than 'object.'  Can you implement a magic method __gettype() which 
expects the return value to be a string?

Reproduce code:
---------------
---
>From manual page: language.oop5.magic
---
class MyInt {
    public function __construct ($val){
        $this->val = $val;
    }
    public function __gettype () {
        return 'int';
    }
}

$foo = new MyInt(5);
$int = (int) 5;

if (gettype($foo) == gettype($int)){
    echo gettype($foo); // Should echo 'int'
} else {
    echo "Fail."
}

Expected result:
----------------
Ideally, the code above would echo "int" as the type of MyInt $foo is 
overridden by the __gettype magic method to be 'int', just as it is for

$int.

Actual result:
--------------
The code above will echo "Fail."  You may also need to implement a 
type-agnostic equivalent of __toString() like __return() that does, 
essentially:

public function __return () {
    return ($this->__gettype()) $this->_value;
}

This would allow me to compare:

($foo === $int); // This should evaluate to true.


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=50599&edit=1

Reply via email to