» Quick Links
You can make money on these forums
We Share profits with you
Google
Google Adsense
Google Adwords
YPN
Yahoo
MSN Search
Web Directories
Web Hosting
Web Hosting Offers
Hosting News
Suggestions
Link Building
Domain Names
PHP Forums
MySQL Forums
» More Links
OSP News
Reseller Hosting
Shared Hosting
Dedicated Servers
Google Adsense
Search Engine Marketing
Link Development
Affiliate Marketing


» Advertising
Multiple DC PR Check

Free SEO Tools


Go Back   Webmaster Forums > Website Developement / Programming > PHP Programming and Tips

PHP Programming and Tips Discuss about PHP programming and Share Tips. Ask questions about Scripting and Errors.

Reply
 
Thread Tools Display Modes
  #1  
Old 07-29-2006, 02:19 PM
maxima maxima is offline
Junior Member
 
Join Date: Jul 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
maxima is on a distinguished road
Default getting private class variables from outside the class

Hi guys

Is there any way to get private class variables from outside the class ? I mean, I know that's the whole point of private, but just for kicks I was writing a my_var_export() and so far for arrays, strings, integers, resources, the output is identical to var_export(), but I can't get classes to work where as the real var_export can (because it can access private variables)... how does it do that ? Or is there a way I can ?

Thanks for replies -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Revenue Sharing Ads ( ?):
  #2  
Old 07-29-2006, 02:22 PM
pablo pablo is offline
OSP Starters
 
Join Date: Jul 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
pablo is on a distinguished road
Default

Hello

Create a public function inside the class that returns the private variable and call the function from the other class. -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
  #3  
Old 07-29-2006, 02:24 PM
slovaski slovaski is offline
OSP Starters
 
Join Date: Jun 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
slovaski is on a distinguished road
Smile

In making members private the point is that it shouldn't be viewable by any external actor to the class. However PHP object oriented is a *joke* and what you are experiencing is one of its aspect. Any native function can access the private members.

If the var_export() function doesn't please you and you really want to write your own then you can't use the class as entry to read private member but you can try to analyse one of the following:

print_r($class)
var_export($class)
var_dump($class)
serialize($class)
...
Hope it helps -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
  #4  
Old 07-29-2006, 02:29 PM
algo algo is offline
OSP Starters
 
Join Date: Jul 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 0
algo is on a distinguished road
Smile

Are you using php 5.xx ? if you do take a look at this

$c = new ReflectionClass("myClass");
Reflection::export($c);

and of course

$c->getMethods() ect ect ect

This will surely help you -- This message may have been cut off and the rest will only be shown to members. To become a member, click here --
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
DemoWolf Launches Private Nameserver Voice Tutorials outsourcingplans Web Hosting News 0 03-16-2007 04:09 AM
The Planet-EV1servers Offers Private Rack outsourcingplans Web Hosting News 0 12-20-2006 03:40 AM
unable to pass any variables from the index venomous PHP Programming and Tips 1 08-10-2006 02:40 PM
Private Domain Depot Announces Sale outsourcingplans Web Hosting News 0 08-08-2006 07:34 AM
decreasing class based on value ghosty PHP Programming and Tips 1 07-30-2006 12:33 PM


All times are GMT. The time now is 08:43 PM.