How to list class variables and their values?

Thread Solved

Join Date: Jul 2008
Posts: 95
Reputation: jakesee is an unknown quantity at this point 
Solved Threads: 4
jakesee jakesee is offline Offline
Junior Poster in Training

How to list class variables and their values?

 
-1
  #1
Apr 30th, 2009
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?

  1. 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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 182
Reputation: kireol is an unknown quantity at this point 
Solved Threads: 24
kireol kireol is online now Online
Junior Poster

Re: How to list class variables and their values?

 
-1
  #2
Apr 30th, 2009
any correctly coded class has a get and set for it's variables
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 95
Reputation: jakesee is an unknown quantity at this point 
Solved Threads: 4
jakesee jakesee is offline Offline
Junior Poster in Training

Re: How to list class variables and their values?

 
0
  #3
Apr 30th, 2009
Originally Posted by kireol View Post
any correctly coded class has a get and set for it's variables
That's not necessarily the case.

  1. public function AddVar($name, $val)
  2. {
  3. $this->$name = $val;
  4. }

So do you know how to get the list of variables? Please?
Last edited by jakesee; Apr 30th, 2009 at 4:35 pm.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 182
Reputation: kireol is an unknown quantity at this point 
Solved Threads: 24
kireol kireol is online now Online
Junior Poster

Re: How to list class variables and their values?

 
0
  #4
Apr 30th, 2009
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)
Last edited by kireol; Apr 30th, 2009 at 5:12 pm. Reason: added link for you
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 95
Reputation: jakesee is an unknown quantity at this point 
Solved Threads: 4
jakesee jakesee is offline Offline
Junior Poster in Training

Re: How to list class variables and their values?

 
0
  #5
Apr 30th, 2009
Originally Posted by kireol View Post
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)
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 182
Reputation: kireol is an unknown quantity at this point 
Solved Threads: 24
kireol kireol is online now Online
Junior Poster

Re: How to list class variables and their values?

 
0
  #6
Apr 30th, 2009
Originally Posted by jakesee View Post
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.
Maybe you are new to OO programming; everyone must start somewhere. I'm sorry that you don't understand beginner level concepts. It looks like you just want to argue with facts and the way things truly are.


Good luck with whatever it is you are doing.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 95
Reputation: jakesee is an unknown quantity at this point 
Solved Threads: 4
jakesee jakesee is offline Offline
Junior Poster in Training

Re: How to list class variables and their values?

 
0
  #7
Apr 30th, 2009
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.
Last edited by jakesee; Apr 30th, 2009 at 5:55 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,403
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 224
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: How to list class variables and their values?

 
0
  #8
Apr 30th, 2009
wow, that's a lot of ranting without actually answering his question.
  1. $vars = get_class_vars('Class');
  2. // or
  3. $vars = get_class_vars(new Class());
There are more in-depth methods (see Reflection in the PHP manual) but this will get the job done
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 95
Reputation: jakesee is an unknown quantity at this point 
Solved Threads: 4
jakesee jakesee is offline Offline
Junior Poster in Training

Re: How to list OBJECT variables and their values?

 
0
  #9
Apr 30th, 2009
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!!
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,403
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 224
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: How to list OBJECT variables and their values?

 
0
  #10
Apr 30th, 2009
Originally Posted by jakesee View Post
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!!
it's actually get_class_vars, not get_class_variables.
If that still doesn't work try
  1. $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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC