PHP ReflectionClass __toString() Function
Last Updated :
22 Feb, 2021
The ReflectionClass__toString() function is an inbuilt function in PHP which is used to return the string representation of the specified ReflectionClass object.
Syntax:
string ReflectionClass__toString( void )
Parameters: This function does not accept any parameter.
Return Value: This function returns the string representation of the specified ReflectionClass object.
Below programs illustrate the ReflectionClass__toString() function in PHP:
Program 1:
php
<?php
class Alphabets {
public function A() {}
public function B() {}
}
$class = new ReflectionClass( 'Alphabets' );
$A = $class ->__toString();
var_dump( $A );
?>
|
Output:
string(435) “Class [ <user> class Alphabets ] { @@ /home/829bc146b7074eafd150c8e57aee5445.php 4-7- Constants [0] { }- Static properties [0] { }- Static methods [0] { }- Properties [0] { }- Methods [2] { Method [ <user> public method A ] { @@ /home/829bc146b7074eafd150c8e57aee5445.php 5 – 5 }Method [ <user> public method B ] { @@ /home/829bc146b7074eafd150c8e57aee5445.php 6 – 6 } } } ”
Program 2:
php
<?php
$class = new ReflectionClass( 'ReflectionClass' );
$A = $class ->__toString();
var_dump( $A );
?>
|
Output:
string(6824) “Class [ <internal:Reflection> class ReflectionClass implements Reflector ] {- Constants [3] { Constant [ integer IS_IMPLICIT_ABSTRACT ] { 16 } Constant [ integer IS_EXPLICIT_ABSTRACT ] { 32 } Constant [ integer IS_FINAL ] { 4 } }- Static properties [0] { }- Static methods [1] { Method [ <internal:Reflection, prototype Reflector> static public method export ] {- Parameters [2] { Parameter #0 [ <required> $argument ] Parameter #1 [ <optional> $return ] } } } . . .Method [ <internal:Reflection> public method getShortName ] {- Parameters [0] { } } } } ”
Reference: https://www.php.net/manual/en/reflectionclass.tostring.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...