Re: [PHP] class and global
Ok, i've found a workaround. So contrary to what is stated apparently in the documentation I had to declara the variables explicitely global to make it working and to create the object and assign _without_ reference. to sum up : global $freedb; $freedb = new freedbaxs(); function return_freedb_search($array) { global $freedb; [snip] $freedb-freedb_search($txt); } this is the one working. On Sun, 20 Mar 2005 11:37:53 +, Mister Jack [EMAIL PROTECTED] wrote: Ok, I've tried with a dummy class : class dummy { var $yank; Function dummy() { $this-yank = test dummy; } } and the problem is exactly the same. i've done print_r($dummy); is works ok outside the function, but inside print_r($dummy) doesn't return anything, like $dummy wasn't existing, even tough I declared it to be global... So the class n itself doesn't have anything to do with it. I'm really stuck with this. Is there any incompatibiliy with class and global declaration ? btw, I'm using PHP 4.3.10-8 thanks for your help, On Sat, 19 Mar 2005 20:45:55 +, Mister Jack [EMAIL PROTECTED] wrote: there is no database connection involved here. if I displace the $freedb = new freedbaxs(); inside the function it's works. I should give a try with a dummy object. (but the constructor, only initialize empty array) On Sat, 19 Mar 2005 21:17:02 +0200, BAO RuiXian [EMAIL PROTECTED] wrote: Evert - Rooftop Solutions wrote: pooly wrote: I'm trying to use a global object (declared at a upper level), but all I got is : Call to a member function on a non-object in /home/pooly/public_html/templeet/modules/freedb.php on line 16 Hmm, perhaps your problem is the failed connection to your database. Can you verify this? Best Bao part of the code is : $freedb = new freedbaxs(); Function return_freedb_search($array) { global $freedb; [snip] $freedb-freedb_search($txt); I don't see an error in this code, perhaps you should give us a bit more information. grt, Evert -- 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] class and global
Ok, I've tried with a dummy class : class dummy { var $yank; Function dummy() { $this-yank = test dummy; } } and the problem is exactly the same. i've done print_r($dummy); is works ok outside the function, but inside print_r($dummy) doesn't return anything, like $dummy wasn't existing, even tough I declared it to be global... So the class n itself doesn't have anything to do with it. I'm really stuck with this. Is there any incompatibiliy with class and global declaration ? btw, I'm using PHP 4.3.10-8 thanks for your help, On Sat, 19 Mar 2005 20:45:55 +, Mister Jack [EMAIL PROTECTED] wrote: there is no database connection involved here. if I displace the $freedb = new freedbaxs(); inside the function it's works. I should give a try with a dummy object. (but the constructor, only initialize empty array) On Sat, 19 Mar 2005 21:17:02 +0200, BAO RuiXian [EMAIL PROTECTED] wrote: Evert - Rooftop Solutions wrote: pooly wrote: I'm trying to use a global object (declared at a upper level), but all I got is : Call to a member function on a non-object in /home/pooly/public_html/templeet/modules/freedb.php on line 16 Hmm, perhaps your problem is the failed connection to your database. Can you verify this? Best Bao part of the code is : $freedb = new freedbaxs(); Function return_freedb_search($array) { global $freedb; [snip] $freedb-freedb_search($txt); I don't see an error in this code, perhaps you should give us a bit more information. grt, Evert -- 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] class and global
Hi, I'm trying to use a global object (declared at a upper level), but all I got is : Call to a member function on a non-object in /home/pooly/public_html/templeet/modules/freedb.php on line 16 part of the code is : $freedb = new freedbaxs(); Function return_freedb_search($array) { global $freedb; [snip] $freedb-freedb_search($txt); so, can I access an object allocated outside a function ? this functionis meant to be a wrapper for that class, because I cannot access directly. thanks for you help, -- Pooly ;) http://www.w-fenec.org/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] class and global
pooly wrote: I'm trying to use a global object (declared at a upper level), but all I got is : Call to a member function on a non-object in /home/pooly/public_html/templeet/modules/freedb.php on line 16 part of the code is : $freedb = new freedbaxs(); Function return_freedb_search($array) { global $freedb; [snip] $freedb-freedb_search($txt); I don't see an error in this code, perhaps you should give us a bit more information. grt, Evert -- Rooftop Solutions - Web Applications on Demand tel. (+31)628962319 fax. (+31)842242474 [EMAIL PROTECTED] http://www.rooftopsolutions.nl -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] class and global
The initialisation seems to be ok, since : Function return_freedb_search($array) { global $freedb; $freedb = new freedbaxs(); [snip] $freedb-freedb_search($txt); //line 16... } works and also $freedb = new freedbaxs(); $freedb-freedb_search(ploplop); Function return_freedb_search($array) { global $freedb; [snip] //$freedb-freedb_search($txt); //line 16... } those line are all in a PHP file which is include if needed, by parsing the template file. So the file is include (then $freedb = new freedbaxs(); should be executed) and return_freedb_search is call a bit later. Everythin has always worked fine, but this is the first time I tried with an object, and all i got is this error. that's really strange, and I really don't have a clue about what is going on. (is the object disapearing ? ) On Sat, 19 Mar 2005 19:59:55 +0100, Evert - Rooftop Solutions [EMAIL PROTECTED] wrote: pooly wrote: I'm trying to use a global object (declared at a upper level), but all I got is : Call to a member function on a non-object in /home/pooly/public_html/templeet/modules/freedb.php on line 16 part of the code is : $freedb = new freedbaxs(); Function return_freedb_search($array) { global $freedb; [snip] $freedb-freedb_search($txt); I don't see an error in this code, perhaps you should give us a bit more information. grt, Evert -- Rooftop Solutions - Web Applications on Demand tel. (+31)628962319 fax. (+31)842242474 [EMAIL PROTECTED] http://www.rooftopsolutions.nl -- 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] class and global
Evert - Rooftop Solutions wrote: pooly wrote: I'm trying to use a global object (declared at a upper level), but all I got is : Call to a member function on a non-object in /home/pooly/public_html/templeet/modules/freedb.php on line 16 Hmm, perhaps your problem is the failed connection to your database. Can you verify this? Best Bao part of the code is : $freedb = new freedbaxs(); Function return_freedb_search($array) { global $freedb; [snip] $freedb-freedb_search($txt); I don't see an error in this code, perhaps you should give us a bit more information. grt, Evert -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] class and global
there is no database connection involved here. if I displace the $freedb = new freedbaxs(); inside the function it's works. I should give a try with a dummy object. (but the constructor, only initialize empty array) On Sat, 19 Mar 2005 21:17:02 +0200, BAO RuiXian [EMAIL PROTECTED] wrote: Evert - Rooftop Solutions wrote: pooly wrote: I'm trying to use a global object (declared at a upper level), but all I got is : Call to a member function on a non-object in /home/pooly/public_html/templeet/modules/freedb.php on line 16 Hmm, perhaps your problem is the failed connection to your database. Can you verify this? Best Bao part of the code is : $freedb = new freedbaxs(); Function return_freedb_search($array) { global $freedb; [snip] $freedb-freedb_search($txt); I don't see an error in this code, perhaps you should give us a bit more information. grt, Evert -- 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] [Class] Behaviour global variables
Hi there, I'm forgetting something, but I can't seem to get to it... Consider the following Class. class Test { var $a; var $b; function Test() { $this-a = 2; $this-b = 5; } function Show() { global $a, $b; echo(a: .$a); echo(a: .$this-a); echo(b: .$b); echo(b: .$this-b); } } After proper initialisation, calling the function Show() gives: a: a: 2 b: b: 5 What am I forgetting here? Tia for answers! -- Kind regards, Tim -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] [Class] Behaviour global variables
Not done any OO stuff with PHP, but I would hazard a guess that the problem is one of scope. Rather than global making available class variables, it makes available GLOBAL variables. And I'm guessing there isn't a global variable a or b, which is why they show up blank. HTH, Richy == Richard Black Systems Programmer, DataVisibility Ltd - http://www.datavisibility.com Tel: 0141 435 3504 Email: [EMAIL PROTECTED] -Original Message- From: Tim Stoop [mailto:[EMAIL PROTECTED]] Sent: 14 August 2002 14:27 To: [EMAIL PROTECTED] Subject: [PHP] [Class] Behaviour global variables Hi there, I'm forgetting something, but I can't seem to get to it... Consider the following Class. class Test { var $a; var $b; function Test() { $this-a = 2; $this-b = 5; } function Show() { global $a, $b; echo(a: .$a); echo(a: .$this-a); echo(b: .$b); echo(b: .$this-b); } } After proper initialisation, calling the function Show() gives: a: a: 2 b: b: 5 What am I forgetting here? Tia for answers! -- Kind regards, Tim -- 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] [Class] Behaviour global variables
$TEST= new TEST; $a=3; $b=4; $TEST-Show(); works, fine better to use $GLOBALS['a'] instead of global $a Op woensdag 14 augustus 2002 15:27, schreef Tim Stoop: Hi there, I'm forgetting something, but I can't seem to get to it... Consider the following Class. class Test { var $a; var $b; function Test() { $this-a = 2; $this-b = 5; } function Show() { global $a, $b; echo(a: .$a); echo(a: .$this-a); echo(b: .$b); echo(b: .$this-b); } } After proper initialisation, calling the function Show() gives: a: a: 2 b: b: 5 What am I forgetting here? Tia for answers! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php