[wp-trac] [WordPress Trac] #48565: The `site_url` function doesn't work with objects implemented `__toString`

WordPress Trac noreply at wordpress.org
Wed Nov 13 21:26:01 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 close  |     Focuses:
-------------------------------+------------------------------

Comment (by pbiron):

 Replying to [comment:5 johnbillion]:
 > it will get cast to a string when necessary (for example if it gets
 passed to a parameter with a type hint of `string`, or gets explicitly
 casted with `(string)`).

 I didn't realize that such casting happened on anything other PHP
 internals (e.g., `strlen()`).  Looking at the
 [https://www.php.net/manual/en/functions.arguments.php#functions.arguments
 .type-declaration PHP Docs], unfortunately, the ability to use `string` as
 a type hint wasn't introduced until 7.0, so until the minimum PHP
 requirement reaches that we couldn't add such type hints.

 Plus, in the case of `get_site_url()` I think the reason for the
 `is_string()` check is to guard against passing, e.g., an `array`, without
 raising runtime errors.  And using the type hint would generating runtime
 errors if a non-string (or something that can't be passed to string) were
 passed.  I'm not sure that would be desirable behavior in this case.

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


More information about the wp-trac mailing list