Skip to content

Instantly share code, notes, and snippets.

@lloc
Created October 1, 2011 10:57
Show Gist options
  • Save lloc/1255879 to your computer and use it in GitHub Desktop.
Save lloc/1255879 to your computer and use it in GitHub Desktop.
Extract and include Example 2
<?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);
?>
@lloc
Copy link
Author

lloc commented Oct 1, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment