# casting php5 objects

- Thread: https://externals.io/message/12692
- Original archive: https://news-web.php.net/php.internals/12692
- Started by Curt Zirzow on 2004-09-10T03:45:21+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #12693 — Andi Gutmans — 2004-09-10T03:27:23+00:00

URL: https://externals.io/message/12692#12693 · In reply to: #12692

Please check the archives to see why we don't support object casts to 
integers/doubles.
Hint: The object id is not unique.

Andi

At 03:45 AM 9/10/2004 +0000, Curt Zirzow wrote:

>In reference to bug #29029 (http://bugs.php.net/29029):
>
>Current casting object behaviour:
>   int      - not able to cast
>   dobule   - notice thrown, returns 1.0
>   null     - will return null
>   bool     - returns 1 (from result of double)
>   string   - user __toString() if applicable or 'Object'
>
>Beyond the ridiculous idea of adding a __toInt(), __toDouble()..
>etc.  What about the idea that casting int so that it returns the
>id of the object, and the double value returns the int casted as a
>double value.  So:
>
>   $o1 = new stdClass();
>   $o2 = new stdClass();
>   $o3 = new stdClass();
>
>   var_dump((int) $o1);    /* 1   */
>   var_dump((double) $o2); /* 2.0 */
>   var_dump((int) $o3);    /* 3   */
>
>Otherwise, I'll just move this over as a documentation problem.
>
>
>Curt
>--
>First, let me assure you that this is not one of those shady pyramid schemes
>you've been hearing about.  No, sir.  Our model is the trapezoid!

---

## #12692 — Curt Zirzow — 2004-09-10T03:45:21+00:00

URL: https://externals.io/message/12692#12692

In reference to bug #29029 (http://bugs.php.net/29029):

Current casting object behaviour:
  int      - not able to cast
  dobule   - notice thrown, returns 1.0
  null     - will return null
  bool     - returns 1 (from result of double)
  string   - user __toString() if applicable or 'Object'

Beyond the ridiculous idea of adding a __toInt(), __toDouble()..
etc.  What about the idea that casting int so that it returns the
id of the object, and the double value returns the int casted as a
double value.  So:

  $o1 = new stdClass();
  $o2 = new stdClass();
  $o3 = new stdClass();

  var_dump((int) $o1);    /* 1   */
  var_dump((double) $o2); /* 2.0 */
  var_dump((int) $o3);    /* 3   */

Otherwise, I'll just move this over as a documentation problem.


Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!

---

## #12694 — Curt Zirzow — 2004-09-10T03:58:12+00:00

URL: https://externals.io/message/12692#12694 · In reply to: #12693

* Thus wrote Andi Gutmans:
> Please check the archives to see why we don't support object casts to 
> integers/doubles.
> Hint: The object id is not unique.

Yeah i checked there, I always get frustrated with to many results
over there :) I'll research that again now that I know there has to
be something there.

Thanks!


Curt
-- 
First, let me assure you that this is not one of those shady pyramid schemes
you've been hearing about.  No, sir.  Our model is the trapezoid!
