# cast_object handler patch

- Thread: https://externals.io/message/26042
- Original archive: https://news-web.php.net/php.internals/26042
- Started by Andrei Zmievski on 2006-10-12T21:03:23+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

---

## #26042 — Andrei Zmievski — 2006-10-12T21:03:23+00:00

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

I discovered that using convert_to_(string|unicode)_with_converter()  
on objects still used runtime encoding instead of the specified  
converter. Turns out it's because cast_object handler has no clue  
about the converter passed to the macro. This patch implements a fix  
via adding an extra generic pointer parameter to cast_object that can  
be used by various types as necessary. If no one objects, I'll commit  
the change soon.

-Andrei

---

## #26045 — Sara Golemon — 2006-10-12T21:26:56+00:00

URL: https://externals.io/message/26042#26045 · In reply to: #26042

>I discovered that using convert_to_(string|unicode)_with_converter()
> on objects still used runtime encoding instead of the specified
> converter. Turns out it's because cast_object handler has no clue
> about the converter passed to the macro. This patch implements a fix
> via adding an extra generic pointer parameter to cast_object that can
> be used by various types as necessary. If no one objects, I'll commit
> the change soon.
>
How does this impact userspace __toString() handlers?  Would we pass the 
encoding from the converter to them?

function __toString($encoding) { }
Do we need __toUnicode($encoding) as well?

Would we just let the user pass back *whatever* type then convert as needed 
in the internal cast handler?

-Sara

---

## #26046 — Andrei Zmievski — 2006-10-12T21:33:24+00:00

URL: https://externals.io/message/26042#26046 · In reply to: #26045

> How does this impact userspace __toString() handlers?  Would we  
> pass the
> encoding from the converter to them?
>
> function __toString($encoding) { }
> Do we need __toUnicode($encoding) as well?
>
> Would we just let the user pass back *whatever* type then convert  
> as needed
> in the internal cast handler?

Right, I was thinking that they would just return Unicode or binary  
strings and the standard object handler takes care of converting it.  
That's the way it's currently implemented.

-Andrei
