Proper include design practice in PHP -



Proper include design practice in PHP -

i've started working on larger preexisting code base of operations (php) , has come attending lot of these files utilize includes/requires in unreadable way. includes/requires sort of cascade through file system, because every file in scheme includes/requires file called common.php. mutual file includes/requires every other file, seems when developer in doubt, included/required mutual , called good.

this written professional web developers, , i'm still student, i'm curious if mutual practice in php. in php should there mutual file includes/requires everything, should each file included/required case case, or there different way mutual practice?

on side note: i'm trying switch out api file new 1 (while keeping old compatibility testing), , hard me tell files utilize new api or old one.

generally, includes should used view based material (html, smarty, perhaps xml or xslt) in mark used build view in mvc approach. however, require(); or require_once(); used command incorporation of server side core functionality in functional or object oriented setting (controllers , models in mvc).

both require(); or require_once(); provide programmatic safety mechanism if code fails, code stops running , errors sent logs - see documentation require , require_once. include(); go on run erroneous code despite errors - not want that.

to other question concerning 1 file "includes everything", php frameworks zend , codeigniter allow called auto loader - loads available classes , instantiates main core classes programmer utilize objects @ will.

if not using framework, can simulate creating config or in case mutual file. however, may not want arbitrarily load everything, create confusion when other developers trying troubleshoot later - might finding out now. have evaluate, test , re-architect code figure out mutual , sparsely used throughout code. have done in past tracing - adding error_log() , var_dump() in effort follow info moves through code.

php include conventions

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -