Created
October 1, 2011 10:57
-
-
Save lloc/1255879 to your computer and use it in GitHub Desktop.
Extract and include Example 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function scope_include ($file) { | |
if (is_file ($file)) { | |
include ($file); | |
return (get_defined_vars ()); | |
} | |
return (FALSE); | |
} | |
class example { | |
var $one = "unchanged"; | |
var $two = "unchanged"; | |
var $three = "unchanged"; | |
function example ($arr = array ()) { | |
if (is_array ($arr)) { | |
foreach (array_keys (get_class_vars (get_class ($this))) as $key) { | |
if (isset ($arr[$key])) { | |
$this->$key = $arr[$key]; | |
} | |
} | |
} | |
} | |
} | |
$config = scope_include (dirname (__FILE_) . "/extract_conf.php"); | |
print_r ($config); | |
/** | |
* Beispiel OOP | |
*/ | |
$example = new example ($config); | |
print_r (get_object_vars ($example)); | |
unset ($example); | |
/** | |
* Beispiel Funktional | |
*/ | |
$one = "unchanged"; | |
$two = "unchanged"; | |
$three = "unchanged"; | |
extract ($config, EXTR_IF_EXISTS); | |
print_r ($GLOBALS); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related post: http://lloc.de/extract-und-inlcude.html