| | |
Variable returned in class -- how do i echo it? :S
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2009
Posts: 2
Reputation:
Solved Threads: 0
Hi everyone. I have a php mysql class and was wondering how I declare a varialbe kinda thing.
Here is the code in the mysql class....
How would I echo $array out of the class?
I can do echo $array inside the class and it works fine, but if I try to do something like
It doesn't work... 
Thanks
Here is the code in the mysql class....
PHP Syntax (Toggle Plain Text)
<?php // class stuff public function fetch_array_from_query($query) { $this->debug_write("Fetching array from given query"); if(!$this->is_connected()) $this->setup_connection(); $result = $this->query($query); $this->debug_write("Finished fetching array from given query"); $array = $this->fetch_array($result); return $array; }
I can do echo $array inside the class and it works fine, but if I try to do something like
PHP Syntax (Toggle Plain Text)
<?php global $db; $db->fetch_array_from_query("Stuff here"); echo $db->$array(); ?>

Thanks
•
•
Join Date: Jul 2007
Posts: 77
Reputation:
Solved Threads: 5
•
•
•
•
Hi everyone. I have a php mysql class and was wondering how I declare a varialbe kinda thing.
Here is the code in the mysql class....
How would I echo $array out of the class?PHP Syntax (Toggle Plain Text)
<?php // class stuff public function fetch_array_from_query($query) { $this->debug_write("Fetching array from given query"); if(!$this->is_connected()) $this->setup_connection(); $result = $this->query($query); $this->debug_write("Finished fetching array from given query"); $array = $this->fetch_array($result); return $array; }
I can do echo $array inside the class and it works fine, but if I try to do something like
It doesn't work...PHP Syntax (Toggle Plain Text)
<?php global $db; $db->fetch_array_from_query("Stuff here"); echo $db->$array(); ?>
Thanks
example:
$array[0]
•
•
Join Date: Aug 2009
Posts: 32
Reputation:
Solved Threads: 0
When a variable get's returned it means it is given to the variable.
PHP Syntax (Toggle Plain Text)
function sum($a, $b){ return $a+$b; } echo sum(2, 3); //outputs 5 $answer = sum(3, 1); // puts 4 in $answer echo $answer; // outputs 4.
![]() |
Similar Threads
- instancing a class with fstream class variable (C++)
- Trying to change a variable from inside a Class (Python)
- Private pointer variable in parent class (C++)
- default variable as a pointer in class (C++)
- [Warning] address of local variable returned??? (C++)
- How to access a variable of a diff class (C++)
- Help with Class, stuck. (C++)
- Accessing a variable of another class (Java)
Other Threads in the PHP Forum
- Previous Thread: Start php! Adding Php interpreter to Aphach
- Next Thread: Mail function Error
| Thread Tools | Search this Thread |
.htaccess alerts apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code convert cron curl database dataentry date display duplicates dynamic echo email emptydisplayvalue error execute explodefunction file files firstoptioninphpdroplist folder form forms function functions google hack href htaccess html htmlspecialchars image include insert ip javasciptvalidation javascript joomla keywords limit link login mail matching menu methods mlm multiple mysql network object oop paypal pdf php problem query radio random recursion recursive redirect remote script search securephp server sessions shot sms source space sql subscription syntax system table tutorial tutorials update upload url validator variable video web youtube





