PHP Classes

File: example_php52.php

Recommend this page to a friend!
  Classes of Artur Graniszewski   Advanced Sourcecode Reflection in PHP   example_php52.php   Download  
File: example_php52.php
Role: Example script
Content type: text/plain
Description: Example #2 (PHP 5.2+)
Class: Advanced Sourcecode Reflection in PHP
Retrieve extended class reflection information
Author: By
Last change:
Date: 13 years ago
Size: 2,615 bytes
 

Contents

Class file image Download
<?php

// PHP 5.2 example


?>
<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_php52.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 AdvancedReflectionClass('MyParent');
    echo
       
"<strong>Class 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 AdvancedReflectionClass('MyParent');
   
$x = $x->getParentClass();
    echo
       
"<strong>Class 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 AdvancedReflectionClass('Test');
    echo
       
"<strong>Interface 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 AdvancedReflectionMethod('MyParent', '__construct');
    echo
       
"<strong>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 AdvancedReflectionFunction('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

?>