[wp-trac] [WordPress Trac] #45973: Wrap global functions like __() in 'function_exists' condition

WordPress Trac noreply at wordpress.org
Sun Jan 13 21:37:02 UTC 2019


#45973: Wrap global functions like __() in 'function_exists' condition
-------------------------+-----------------------------
 Reporter:  jonasemde    |      Owner:  (none)
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  General      |    Version:
 Severity:  trivial      |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 The __() function is used in multiple frameworks and other open source
 libraries.

 When both systems (e.g. WordPress and Laravel or WordPress and Magento)
 are required in one composer project the 'function already exists'
 Exception got thrown.

 To override the function behaviour and/or be compatible with other
 frameworks like Laravel the functions should be wrapped within a
 'function_exists' condition like so:

 {{{#!php
 <?php
 if (! function_exists('__')) {
     function __( $text, $domain = 'default' ) {
         return translate( $text, $domain );
     }
 }
 }}}


 Especially the Laravel core does the same:
 [https://github.com/laravel/framework/blob/5.7/src/Illuminate/Foundation/helpers.php]

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


More information about the wp-trac mailing list