PHP Classes

File: example_php53.php

Recommend this page to a friend!
  Classes of Artur Graniszewski  >  Advanced Sourcecode Reflection in PHP  >  example_php53.php  >  Download  
File: example_php53.php
Role: Example script
Content type: text/plain
Description: Example #1 (PHP 5.3+ only)
Class: Advanced Sourcecode Reflection in PHP
Retrieve extended class reflection information
Author: By
Last change: Another update.
Date: 11 years ago
Size: 2,759 bytes
 

Contents

Class file image Download
<?php

// PHP 5.3 example
namespace aa {

?>
<html>
<head>
<style type="text/css">
body {font-size: 0.9em;}
</style>
<title>Advanced Reflection example</title>
</head>
<body>

<?php
    date_default_timezone_set
('Europe/Paris');
   
ini_set('display_errors', true);
   
error_reporting(E_ALL);

    require(
"./reflection_php53.php");

    function
tester($aa) {
        echo
$aa;
    }
   
    abstract class
GenericParent
   
{
        public function
__construct($name) {
            echo
$name;
        }
    }

    class
/* aaaa */ MyParent extends GenericParent
   
{
        public function
__construct($name) {
            echo
strtoupper($name);
        }
    }

    interface
Test
   
{
       
    }


   
// get information about the class
   
$x = new \System\Reflection\AdvancedReflectionClass('aa\MyParent');
    echo
       
"<strong>Class aa\MyParent is in file ".$x->getFileName().
       
" and starts at col: ".$x->getStartColumn().
       
", line: ".$x->getStartLine().
       
", filepos: ".$x->getStartPosition()."</strong><br />";

   
highlight_string('<?php '.PHP_EOL.$x->getDeclaration());

    echo
'<hr>';

   
// get information about the parent class
   
$x = new \System\Reflection\AdvancedReflectionClass('aa\MyParent');
   
$x = $x->getParentClass();
    echo
       
"<strong>Class aa\GenericParent is in file ".$x->getFileName().
       
" and starts at col: ".$x->getStartColumn().
       
", line: ".$x->getStartLine().
       
", filepos: ".$x->getStartPosition()."</strong><br />";

   
highlight_string('<?php '.PHP_EOL.$x->getDeclaration());

    echo
'<hr>';

   
// get information about the interface
   
$x = new \System\Reflection\AdvancedReflectionClass('aa\Test');
    echo
       
"<strong>Interface aa\Test is in file ".$x->getFileName().
       
" and starts at col: ".$x->getStartColumn().
       
", line: ".$x->getStartLine().
       
", filepos: ".$x->getStartPosition()."</strong><br />";

   
highlight_string('<?php '.PHP_EOL.$x->getDeclaration());

    echo
'<hr>';

   
// get information about the class method
   
$x = new \System\Reflection\AdvancedReflectionMethod('aa\MyParent', '__construct');
    echo
       
"<strong>Method aa\MyParent\__construct() is in file ".$x->getFileName().
       
" and starts at col: ".$x->getStartColumn().
       
", line: ".$x->getStartLine().
       
", filepos: ".$x->getStartPosition()."</strong><br />";

       
   
highlight_string('<?php '.PHP_EOL.$x->getDeclaration());

    echo
'<hr>';

   
// get information about the function
   
$x = new \System\Reflection\AdvancedReflectionFunction('aa\tester');
    echo
       
"<strong>Function tester() is in file ".$x->getFileName().
       
" and starts at col: ".$x->getStartColumn().
       
", line: ".$x->getStartLine().
       
", filepos: ".$x->getStartPosition()."</strong><br />";

       
   
highlight_string('<?php '.PHP_EOL.$x->getDeclaration());

?>
</body>
</html>

<?php
}
?>

For more information send a message to info at phpclasses dot org.