Dealing with function redefinitions php

Dealing with function redefinitions php

include_once and require_once are very useful if you have a library of common functions. If you try to override with – that is define – an identically named local function however, PHP will halt noting that it cannot redeclare functions. You can allow for this by bracketing (within the include file):

function myUsefulFunc($arg1, $arg2) {
     ... }

if (!function_exists('myUsefulFunc')) {
function myUsefulFunc($arg1, $arg2) {
     ... }}

Top level functions (ie. those not defined within other functions or dependent on code running) in the local file are always parsed first, so within the included/required file is safe – it doesn’t matter where the include statements are in the local code.

Thanks to :

also Thanks to :

Share on Facebook

One thought on “Dealing with function redefinitions php”