how would I go about getting around the \"protected\" so I can output the data.
tabs\\api\\property\\Property Object (
[id:protected] => 90_4_HH
[pr
I did not fully understand your question, but if you want to access protected properties from outside the class, you have to use Reflection:
$reflObj = new ReflectionObject($property);
$props = $reflObj->getProperties(ReflectionProperty::IS_PROTECTED);
foreach ($props as $prop) {
$prop->setAccessible(true);
echo $prop->getName() . ":" . $prop->getValue($property), "\n";
}
Sample for outputting the address:
$reflObj = new ReflectionObject($property);
$addrProp = $reflObj->getProperty('address');
$addrProp->setAccessible(true);
echo $addrProp->getValue($property);
Your title implies that you want to make -the class (not object)- public, as opposed to "internal"/etc.. All classes are public in PHP.
Your question says that you want to get around method/property scope (disagrees with title). You didn't say what you've tried. You also didn't indicate whether this is a class you developed or not. If you have control over it, add a freaking method or two to allow you to get the data. If you don't, then inspect the methods, and/or attempt reflection. These answers apply to every OOP language in existence.
Before asking other people, read the documentation.
http://www.php.net/manual/en/language.oop5.basic.php
Answer to the question posed by the title is that all classes are public.
What you are asking is how to access protected member variables.
Taken from here (http://ajmm.org/2011/06/using-php-reflection-to-read-a-protected-property/), this is an example of how to do this:
public static function getReflectedPropertyValue($class, $propertyName)
{
$reflectedClass = new ReflectionClass($class);
$property = $reflectedClass->getProperty($propertyName);
$property->setAccessible(true);
return $property->getValue($class);
}
...
getReflectedPropertyValue($yourObject, 'protectedProperty');
That said, the question is why you want to do this. Members are marked protected specifically to prevent you from doing this. If you have access to the source code that defines this other class, then it might make more sense to either change these members to "public" or (better) to provide a getXYZ() method for whichever properties you want to access.