Access property from include inside a class method in PHP
Posted
by
Jojo
on Stack Overflow
See other posts from Stack Overflow
or by Jojo
Published on 2012-12-08T05:02:43Z
Indexed on
2012/12/08
5:03 UTC
Read the original article
Hit count: 110
How do you make a class property available to the other included file inside the same class' method?
// file A.php
class A
{
private $var = 1;
public function go()
{
include('another.php');
}
}
in another file:
// this is another.php file
// how can I access class A->var?
echo $var; // this can't be right
Is this possible given the scope. If var is an array then we can use extract but if var is not, we can wrap it in an array. Is there a better way?
Thanks!
© Stack Overflow or respective owner