| | |
How to list class variables and their values?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jul 2008
Posts: 95
Reputation:
Solved Threads: 4
Hi,
Without first knowng what public class variables the class has, how can i display a list of all the variables in that class along with the values?
will display the public variables and values, plus some other unwanted entries, but I cannot do anything with them.
I want to be able to create name=value pairs for an HTML GET request using the class variables.
Thanks for reading this.
Without first knowng what public class variables the class has, how can i display a list of all the variables in that class along with the values?
PHP Syntax (Toggle Plain Text)
print_r(new MyClass());
will display the public variables and values, plus some other unwanted entries, but I cannot do anything with them.
I want to be able to create name=value pairs for an HTML GET request using the class variables.
Thanks for reading this.
Last edited by jakesee; Apr 30th, 2009 at 3:53 pm.
•
•
Join Date: Jul 2008
Posts: 95
Reputation:
Solved Threads: 4
That's not necessarily the case.
So do you know how to get the list of variables? Please?
PHP Syntax (Toggle Plain Text)
public function AddVar($name, $val) { $this->$name = $val; }
So do you know how to get the list of variables? Please?
Last edited by jakesee; Apr 30th, 2009 at 4:35 pm.
•
•
Join Date: Mar 2008
Posts: 182
Reputation:
Solved Threads: 24
yes, that is the case.
Any class that is coded correctly has get and set for all class variables that need to be get and set. that's OO at it's basic core.
http://en.wikipedia.org/wiki/Encapsu...mputer_science)
Any class that is coded correctly has get and set for all class variables that need to be get and set. that's OO at it's basic core.
http://en.wikipedia.org/wiki/Encapsu...mputer_science)
Last edited by kireol; Apr 30th, 2009 at 5:12 pm. Reason: added link for you
•
•
Join Date: Jul 2008
Posts: 95
Reputation:
Solved Threads: 4
•
•
•
•
yes, that is the case.
Any class that is coded correctly has get and set for all class variables that need to be get and set. that's OO at it's basic core.
http://en.wikipedia.org/wiki/Encapsu...mputer_science)
•
•
Join Date: Mar 2008
Posts: 182
Reputation:
Solved Threads: 24
•
•
•
•
Wikipedia is not a bible and standards change. I would appreciate if you can answer the question. If you do no know, its ok. thanks for the input.
Good luck with whatever it is you are doing.
•
•
Join Date: Jul 2008
Posts: 95
Reputation:
Solved Threads: 4
I do not want to argue with you, but in case you think I am sneaking around, I would like to inform you that I have to give you a negative reputation now because you are not answering the question.
It has to be "this is how it is done" or "it cannot be done" instead of arguing whether it is "correctly coded" or "good programming practice".
EDIT: After posting this, I went on into google to do a search "list class variables" and this post actually came out first on the list! You see, by not answering the question (any question at all), you are wasting not just your time and my time, any one else who comes along to this post will be wasted. I hope you do understand me.
It has to be "this is how it is done" or "it cannot be done" instead of arguing whether it is "correctly coded" or "good programming practice".
EDIT: After posting this, I went on into google to do a search "list class variables" and this post actually came out first on the list! You see, by not answering the question (any question at all), you are wasting not just your time and my time, any one else who comes along to this post will be wasted. I hope you do understand me.
Last edited by jakesee; Apr 30th, 2009 at 5:55 pm.
wow, that's a lot of ranting without actually answering his question.
There are more in-depth methods (see Reflection in the PHP manual) but this will get the job done
php Syntax (Toggle Plain Text)
$vars = get_class_vars('Class'); // or $vars = get_class_vars(new Class());
Last edited by ShawnCplus; Apr 30th, 2009 at 5:57 pm.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
•
•
Join Date: Jul 2008
Posts: 95
Reputation:
Solved Threads: 4
finally! I actually given up on this thread because I thought no one would come inside a thread so many replies.
thanks for the insight ShawnCPlus. Unfortunately, that function doesn't do what I want. because it does not accept an object. maybe I phrased my question wrongly.
$object = new MyClass();
// after some funny operations
// that dynamically creates more member variables
$var = get_class_variables($object); //error.
I'll look up "Reflection" on PHP first. thanks!!
thanks for the insight ShawnCPlus. Unfortunately, that function doesn't do what I want. because it does not accept an object. maybe I phrased my question wrongly.
$object = new MyClass();
// after some funny operations
// that dynamically creates more member variables
$var = get_class_variables($object); //error.
I'll look up "Reflection" on PHP first. thanks!!
•
•
•
•
finally! I actually given up on this thread because I thought no one would come inside a thread so many replies.
thanks for the insight ShawnCPlus. Unfortunately, that function doesn't do what I want. because it does not accept an object. maybe I phrased my question wrongly.
$object = new MyClass();
// after some funny operations
// that dynamically creates more member variables
$var = get_class_variables($object); //error.
I'll look up "Reflection" on PHP first. thanks!!
If that still doesn't work try
php Syntax (Toggle Plain Text)
$var = get_class_vars(get_class($object));
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
![]() |
Similar Threads
- C / C++ FAQ's and Practice problems (C++)
- problem with linked list (C++)
- storing the selected value of a drop-down list (PHP)
- Can you create a class object based on user input? (C++)
- iterating through class attributes (Python)
- 'this' in initializer list - bad, or irrelevant? (C++)
- static variables in python (Python)
- Issues with double linked list (C++)
- Processing array values (PHP)
Other Threads in the PHP Forum
- Previous Thread: Should HTML forms be data or view
- Next Thread: PHP: Session 2-Dimensional Array - Track Viewed Products
| Thread Tools | Search this Thread |
apache api array basic beginner binary broken cakephp checkbox class cms code computing confirm cron curl customizableitems database date delete display dynamic echo email error external file files filter folder form forms forum function functions gc_maxlifetime google headmethod host href htaccess html iframe image include insert ip javascript joomla limit link login mail malfunction memmory memory menu mlm multiple mysql navigation oop parsing paypal pdf php phpmysql problem query question radio random recursion remote script search select server sessions sms snippet soap source space sql syntax system table thesishelp trouble tutorial update upload url validator variable video web xml youtube






