Make object available within php functions without passing them or making them global
Posted
by Matt
on Stack Overflow
See other posts from Stack Overflow
or by Matt
Published on 2010-04-19T03:48:11Z
Indexed on
2010/04/19
3:53 UTC
Read the original article
Hit count: 335
Hey all,
This requirement is just for simplicity for developers and beautiful code. I'm building a template system and I really would just like an object variable to simply be there in all functions. Here's some code:
Librarian.php:
$class = "slideshow";
$function = "basic";
$args = array(...);
$librarian = $this; // I WOULD LIKE THIS TO BE PRESENT IN CALLED FUNCTION
...
return call_user_func($class.'::'.$function, $args);
...
Slideshow.php:
public static function basic($args) {
echo $librarian; // "Librarian Object"
}
Thanks! Matt Mueller
© Stack Overflow or respective owner