note 111360 modified in function.get-object-vars by danbrown

From: Date: Tue, 05 Mar 2013 16:07:27 +0000
Subject: note 111360 modified in function.get-object-vars by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-193913@lists.php.net to get a copy of this message
A simple way to call this function within an Object and to only export the *public* params would be to artificially change the scope - for example with a closure in php 5.3: <?php class Example { public $publicSetting = 'public'; protected $protectedSetting = 'protected'; private $privateSetting = 'private'; public function showEverything() { return get_object_vars($this); } public function showMyPublicsOnly() { $me = $this; $publics = function() use ($me) { return get_object_vars($me); }; return $publics(); } } ?> --was-- A simple way to call this function within an Object and to only export the *public* params would be to artificially change the scope - for example with a closure in php 5.3: class Example { public $publicSetting = 'public'; protected $protectedSetting = 'protected'; private $privateSetting = 'private'; public function showEverything() { return get_object_vars($this); } public function showMyPublicsOnly() { $me = $this; $publics = function() use ($me) { return get_object_vars($me); }; return $publics(); } } http://php.net/manual/en/function.get-object-vars.php

« previous php.notes (#193913) next »