note 113301 added to function.include

From: Date: Sun, 22 Sep 2013 21:35:58 +0000
Subject: note 113301 added to function.include
Groups: php.notes 
Request: Send a blank email to php-notes+get-196353@lists.php.net to get a copy of this message
Include function,utilizing extract and compact to post variables to and return from an include file (great for configurations, ex: DB connection info, or whatever else you can imagine). <?php # include function allowing variables to be posted to and returned from the target script function inc( $__path, $__return='.', array $__post=array() ) { # post var's to the local scope if ( count( $__post ) ) extract($__post, EXTR_SKIP); # include the file and store the result if ( $__result = include $__path ) { # return requested variables from the included file if ( is_array($__return) ) $result = compact($__return); # Return ALL variables defined from within the included file # NOTE: $__post keys are NOT included! else if ( $__return == '.' ) $result = compact( array_diff( array_keys(get_defined_vars()), array('GLOBALS', '__path', '__return', '__post', '__result') + array_keys($__post) ) ); # Is $__return a variable from the file? else if ( $__return && isset($$__return) ) $result = array( $__return => $$__return ); else $result = array(); # unshift the include result into $result array_unshift($result, $__result); return $result; } return array($__result); } ?> ------------------------------------------- www.show-ip.org ---- Server IP: 69.147.83.199 Probable Submitter: 87.109.9.207 ---- Manual Page -- http://php.net/manual/en/function.include.php Edit -- https://master.php.net/note/edit/113301 Del: integrated -- https://master.php.net/note/delete/113301/integrated Del: useless -- https://master.php.net/note/delete/113301/useless Del: bad code -- https://master.php.net/note/delete/113301/bad+code Del: spam -- https://master.php.net/note/delete/113301/spam Del: non-english -- https://master.php.net/note/delete/113301/non-english Del: in docs -- https://master.php.net/note/delete/113301/in+docs Del: other reasons-- https://master.php.net/note/delete/113301 Reject -- https://master.php.net/note/reject/113301 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#196353) next »