Dealing with function redefinitions php 1 comment

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

About Pragnesh Karia

Pragnesh Karia, Open Source Enthusiast, Software Professional, Software Developer, Technical Lead ,Magento, Joomla ,Joomla LMS , Moodel LMS ,PHP ,Mysql, Ajax, Javascript, Jquery, Linux, Fan of Open Sources , Annet Technologies , SEO Analyst , Mootools

One thought on “Dealing with function redefinitions php