[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:05:35 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       |   Keywords:  needs-patch
  Focuses:                |
--------------------------+-----------------------------
 The `site_url` function omits the the path if the passed parameter is an
 object with `__toString` method implemented.

 for example:

 {{{#!php
 <?php
 class Str
 {
     protected $string;

     public function __construct($string)
     {
         $this->string = $string;
     }

     public function doSomething()
     {
         // do something with $this->string;
     }
     public function __toString()
     {
         return $this->string;
     }
 }


 $path = new Str('/store/locations/');
 $path->doSomething();
 echo site_url($path);
 // The above will return https://example.com/
 // whereas it should return https://example.com/store/locations/
 }}}

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


More information about the wp-trac mailing list