Class question
Posted: Sat Dec 02, 2006 9:14 am
Code: Select all
class MyClass
{
var $MyArray = array(1,2,3);
function MyMethod()
{
$this->IsBasic = 'like me!';
}
}A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
class MyClass
{
var $MyArray = array(1,2,3);
function MyMethod()
{
$this->IsBasic = 'like me!';
}
}I know how to open a file. I am asking specifically what would be the best way to do this in class context so I can store the variables used by the class in a seperate file.Oren wrote:It really depends. You'll need to tell more.
For now, check out file() and parse_ini_file()
Code: Select all
class MyClass
{
var $MyArray = array();
function setArray($array)
{
$this->MyArray = (array)$array;
}
}
require_once "/path/to/array/file.php"
$obj = new MyClass();
$obj->setArray($array_in_file);If I do it like that I will end up with two copies of the variable, one in the object and one in global scope. I don't want that, the array is too big.d11wtq wrote:Inject it manually
Not strictly true.bokehman wrote:If I do it like that I will end up with two copies of the variable, one in the object and one in global scope. I don't want that, the array is too big.d11wtq wrote:Inject it manually
Code: Select all
public class Foo {
private $foo;
public Foo() {
$this->foo = file_get_contents('whatever.php');
}
}