[PHP] OOP-related question
Hey, I have the following script: class overall { function overall(){ $this-loaded['overall'] =1; function load($class){ $$class = new $class; $this-loaded[$class] = 1; $$class-setup(); // Run constructor if(!is_object($$class)){ return false; } return true; } } then I have a few classes, which hold a setup() function as thei 'constructor'. Then, I do this: $overall = new overall; $overall-load('debug'); this should load the debug class. I want it to load to $debug-, but it won't even load to $overall-debug It's not really a *need* to have this, it's just something that will help me in keeping control over all classes. I don't want to use new class, because this way it would be easier to 'instruct' the 'constructor' of those new classes to change the values of the vars to a specific one, without calling for something weird... anyway, it doesn't work, and it doesn't spit out an error either. Any ideas? - Tularis -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OOP-related question
Hello, Adding the following as the first line of overall-load() should solve your problem. global $$class; HTH, Danny. - Original Message - From: Tularis [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, November 14, 2002 8:18 PM Subject: [PHP] OOP-related question Hey, I have the following script: class overall { function overall(){ $this-loaded['overall'] =1; function load($class){ $$class = new $class; $this-loaded[$class] = 1; $$class-setup(); // Run constructor if(!is_object($$class)){ return false; } return true; } } then I have a few classes, which hold a setup() function as thei 'constructor'. Then, I do this: $overall = new overall; $overall-load('debug'); this should load the debug class. I want it to load to $debug-, but it won't even load to $overall-debug It's not really a *need* to have this, it's just something that will help me in keeping control over all classes. I don't want to use new class, because this way it would be easier to 'instruct' the 'constructor' of those new classes to change the values of the vars to a specific one, without calling for something weird... anyway, it doesn't work, and it doesn't spit out an error either. Any ideas? - Tularis -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OOP-related question
I think it is working, but you are not seeing anything because all the variables and objects that are declared in your classes are destroyed once the function exits (out of scope?). I just finished reading up on this, but I think you want to look into passing data by reference instead of value like you are doing. I see that you were trying to accomplish this by using variable variables, but variables are unique to the function they were created in. I wish I could explain it more, but like I said, I just finished reading up on it. These two articles may help you a lot: http://www.onlamp.com/pub/a/php/2002/08/15/php_foundations.html http://www.onlamp.com/pub/a/php/2002/09/12/php_foundations.html On Thursday, November 14, 2002, at 03:18 PM, Tularis wrote: Hey, I have the following script: class overall { function overall(){ $this-loaded['overall'] =1; function load($class){ $$class = new $class; $this-loaded[$class] = 1; $$class-setup(); // Run constructor if(!is_object($$class)){ return false; } return true; } } then I have a few classes, which hold a setup() function as thei 'constructor'. Then, I do this: $overall = new overall; $overall-load('debug'); this should load the debug class. I want it to load to $debug-, but it won't even load to $overall-debug It's not really a *need* to have this, it's just something that will help me in keeping control over all classes. I don't want to use new class, because this way it would be easier to 'instruct' the 'constructor' of those new classes to change the values of the vars to a specific one, without calling for something weird... anyway, it doesn't work, and it doesn't spit out an error either. Any ideas? - Tularis -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Brent Baisley Systems Architect Landover Associates, Inc. Search Advisory Services for Advanced Technology Environments p: 212.759.6400/800.759.0577 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OOP-related question
Ok, I combined both, your tip and Brent's, now I have the following error, with the following code: Fatal error: Cannot pass parameter 1 by reference in /home/shadowlight/public_html/test/libs/global.lib.php on line 296 code: function load($class){ global $$class; $$class = new $class; $this-loaded[$class] = 1; $$class-setup(); // Run constructor if(!is_object($$class)){ return false; } return true; } } Danny Shepherd wrote: Hello, Adding the following as the first line of overall-load() should solve your problem. global $$class; HTH, Danny. - Original Message - From: Tularis To: Sent: Thursday, November 14, 2002 8:18 PM Subject: [PHP] OOP-related question Hey, I have the following script: class overall { function overall(){ $this-loaded['overall'] =1; function load($class){ $$class = new $class; $this-loaded[$class] = 1; $$class-setup(); // Run constructor if(!is_object($$class)){ return false; } return true; } } then I have a few classes, which hold a setup() function as thei 'constructor'. Then, I do this: $overall = new overall; $overall-load('debug'); this should load the debug class. I want it to load to $debug-, but it won't even load to $overall-debug It's not really a *need* to have this, it's just something that will help me in keeping control over all classes. I don't want to use new class, because this way it would be easier to 'instruct' the 'constructor' of those new classes to change the values of the vars to a specific one, without calling for something weird... anyway, it doesn't work, and it doesn't spit out an error either. Any ideas? - Tularis -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OOP-related question
I think the error is fairly self explanatory here - you can't pass the parameter by reference. Globalising the $$class var will retain scope. Danny. - Original Message - From: Tularis [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Thursday, November 14, 2002 9:29 PM Subject: Re: [PHP] OOP-related question Ok, I combined both, your tip and Brent's, now I have the following error, with the following code: Fatal error: Cannot pass parameter 1 by reference in /home/shadowlight/public_html/test/libs/global.lib.php on line 296 code: function load($class){ global $$class; $$class = new $class; $this-loaded[$class] = 1; $$class-setup(); // Run constructor if(!is_object($$class)){ return false; } return true; } } Danny Shepherd wrote: Hello, Adding the following as the first line of overall-load() should solve your problem. global $$class; HTH, Danny. - Original Message - From: Tularis To: Sent: Thursday, November 14, 2002 8:18 PM Subject: [PHP] OOP-related question Hey, I have the following script: class overall { function overall(){ $this-loaded['overall'] =1; function load($class){ $$class = new $class; $this-loaded[$class] = 1; $$class-setup(); // Run constructor if(!is_object($$class)){ return false; } return true; } } then I have a few classes, which hold a setup() function as thei 'constructor'. Then, I do this: $overall = new overall; $overall-load('debug'); this should load the debug class. I want it to load to $debug-, but it won't even load to $overall-debug It's not really a *need* to have this, it's just something that will help me in keeping control over all classes. I don't want to use new class, because this way it would be easier to 'instruct' the 'constructor' of those new classes to change the values of the vars to a specific one, without calling for something weird... anyway, it doesn't work, and it doesn't spit out an error either. Any ideas? - Tularis -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] OOP-related question
This is done on PHP 3.0.16 Hi folks, I have a problem with these HTTP_ vars. I have a mainpage, call it main. There is an include which carries several settings and other includes like my abstract db-layer class. I include this in my class-function, which works fine for the most variables but $SERVER_ADDR It seems that I cannot get these variable in the function of my class so I have to pass them as argument to the function. I have made an init() function where I pass these vars inside the object But I don´t like to do this, vars like $SERVER_ADDR or *_NAME should be available inside the objects-functions. Is this behaviour normal, or are there any workarounds for it? Hope someone could help. TIA Oliver -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] OOP-related question
On Mon, 29 Apr 2002 [EMAIL PROTECTED] wrote: I include this in my class-function, which works fine for the most variables but $SERVER_ADDR It seems that I cannot get these variable in the function of my class so I have to pass them as argument to the function. I have made an init() function where I pass these vars inside the object But I don´t like to do this, vars like $SERVER_ADDR or *_NAME should be available inside the objects-functions. Is this behaviour normal, or are there any workarounds for it? function cheeseTaster() { global $SERVER_ADDR; } miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php