[wp-trac] [WordPress Trac] #48565: The `site_url` function doesn't work with objects implemented `__toString`
WordPress Trac
noreply at wordpress.org
Mon Nov 11 21:18:43 UTC 2019
#48565: The `site_url` function doesn't work with objects implemented `__toString`
--------------------------+------------------------------
Reporter: azeemhassni | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version: 5.2.4
Severity: trivial | Resolution:
Keywords: needs-patch | Focuses:
--------------------------+------------------------------
Comment (by pbiron):
I'm not sure whether a `wp_is_string()` is a good idea or not. In what
context do you need to pass an such an object to `site_url()`?
I just did a quick search and there are almost 250 calls to `is_string()`
in core...so it would take some effort to assess the performance impact of
the extra function call overhead. A single extra function call is
negligible, but something called in a large loop or recursively ''might''
result in a noticeable impact.
The helper would be real easy:
{{{#!php
function wp_is_string( $str ) {
return is_string( $str ) || ( is_object( $str ) && method_exists(
$str, '__toString' ) );
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/48565#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list