News Feed
Jobs Feed
Sections




News Archive
Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Vance Lucas' Blog:
Get Only Public Class Properties for the Current Class in PHP
January 06, 2010 @ 10:06:29

On his blog today Vance Lucas has posted a method you can use to only get the properties of your class that are in the "public" scope.

PHP provides two built-in functions to retrieve properties of a given class '" get_object_vars and get_class_vars. Both these functions behave the same exact way, one taking an object as a variable and the other taking a string class name. The tricky thing about the two functions is that they behave differently depending on the call scope, returning all of the class variables available within the called scope.

As a bit of a hack (in lower than PHP 5.3) he shows how to use the create_function function to create a small statement in a different scope that returns the only the variables seen from the "outside" - just the public ones. PHP 5.3 users can do it much more cleanly with closures. Code examples for both are included.

0 comments voice your opinion now!
public class property createfunction closure tutorial


blog comments powered by Disqus

Similar Posts

The Bakery - Rails-Like Validation, Elistic, Textile, and a CakePHP Release

DevShed: Using Method Call Overloading in PHP 4

NETTUTS.com: How to Create an Object-Oriented Blog in PHP

PHP-Coding-Practices.com: How To Generate Monochromatic CSS Stylesheets Within Seconds Using PHP

Anthony Ferrara: What Generators Can Do For You


Community Events











Don't see your event here?
Let us know!


symfony2 component facebook install podcast hhvm performance hack example language introduction framework composer release package database unittest project application security

All content copyright, 2014 PHPDeveloper.org :: info@phpdeveloper.org - Powered by the Solar PHP Framework