| | |
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 |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql number oop parameter paypal pdf php phpincludeissue problem query radio random recourse recursion regex remote script search seo server sessions sms source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white wordpress xml youtube





