rgb192
asked on
reflection class to echo all the properties
<?php
require_once "fullshop.php";
class ReflectionUtil {
static function getMethodSource( ReflectionMethod $method ) {
$path = $method->getFileName();
$lines = @file( $path );
$from = $method->getStartLine();
$to = $method->getEndLine();
$len = $to-$from+1;
return implode( array_slice( $lines, $from-1, $len+9 ));
}
}
//$class = new ReflectionClass( 'CdProduct' );
//$method = $class->getMethod( 'getSummaryLine' );
$class = new ReflectionClass('shopProduct');
$method = $class->getMethod('__construct');
print ReflectionUtil::getMethodSource( $method );
$properties=$class->getProperties('__construct');
foreach ($properties as $property){
echo '<br>property: '.$property;
}
?>
output
public function __construct( $title, $firstName, $mainName, $price ) { $this->title = $title; $this->producerFirstName = $firstName; $this->producerMainName = $mainName; $this->price = $price; } public function getProducerFirstName() { return $this->producerFirstName; } public function getProducerMainName() { return $this->producerMainName; }
Warning: ReflectionClass::getProper
Warning: Invalid argument supplied for foreach() in C:\wamp\www\POPP-edition4-
I want to echo all the properties of the method __construct in the shopProduct class
I want to echo all the properties in the shopProduct class
ASKER
So object is properties and methods
Reflection is class
Reflection is class
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks for reflection information
http://php.net/manual/en/language.oop5.properties.php
http://php.net/manual/en/language.oop5.visibility.php
Within a method, there may be local variables.
Open in new window
For a deeper understanding of how to produce meta-data about your classes, you may want to make a tour-de-force study of this, setting up code examples to demonstrate the various methods:http://php.net/manual/en/intro.reflection.php