Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to override a default PHP function?

I would like to override the _() PHP function so that it supports one or more arguments. Is it possible to do that using PHP code?

like image 898
laurent Avatar asked Oct 24 '25 02:10

laurent


2 Answers

No, but with PHP version >= 5.3.0 you could use namespacing though.

like image 90
Wesley van Opdorp Avatar answered Oct 26 '25 18:10

Wesley van Opdorp


It is possible, using the Runkit extension.

However, it's generally not considered a good idea, except for use with things like unit testing, where you may want to isolate some of your functionality.

For general use, you shouldn't be overriding built-in functions because it makes your code harder to maintain, and opens you up to some very hard to debug issues.

Also, the Runkit extension is marked as 'experimental', which means it really shouldn't be used in a production system.

like image 29
Spudley Avatar answered Oct 26 '25 17:10

Spudley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!