[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 19:28:26 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):

 Thanx for the ticket and welcome to Trac!

 That's because
 [https://developer.wordpress.org/reference/functions/get_site_url/
 get_site_url()] (which is called by `site_url()`) has an explicit check
 for whether the `$path` param is a string (see L3165).  If it's not a
 string, then it is ignored.

 While it would certainly be possible to add an additional check for
 whether `$path` is an object that has a `__toString()` method, why would
 that be desired?  If it were done in this one case, then it could be
 argued that it should be done for **ANY** "string" param to **ANY**
 function/method in core...and doing so doesn't seem reasonable to me.

 I'd suggest you just call `__toString()` yourself when you call
 `site_url()`.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48565#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list