Skip to content
Related Articles

Related Articles

PHP ReflectionClass __toString() Function

Improve Article
Save Article
  • Last Updated : 22 Feb, 2021
Improve Article
Save Article

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
  
// Creating a user-defined function
class Alphabets {
    public function A() {}
    public function B() {}
}
  
// Using ReflectionClass() over the 
// class Alphabets
$class = new ReflectionClass('Alphabets');
  
// Calling the __toString() function
$A = $class->__toString();
  
// Getting the string representation
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
  
// Using ReflectionClass()
$class = new ReflectionClass('ReflectionClass');
  
// Calling the __toString() function
$A = $class->__toString();
  
// Getting the string representation
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
 


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!