PHP Doku:: Gets aggregation information for a given object - function.aggregate-info.html

Verlauf / Chronik / History: (24) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzVariablen- und typbezogene ErweiterungenObject Aggregation/Composition [PHP 4]Object Aggregation Funktionenaggregate_info

Ein Service von Reinhard Neidl - Webprogrammierung.

Object Aggregation Funktionen

<<Object Aggregation Funktionen

aggregate_methods_by_list>>

aggregate_info

(PHP 4 >= 4.3.0)

aggregate_info Gets aggregation information for a given object

Beschreibung

array aggregate_info ( object $object )

Gets the aggregation information for the given object.

Parameter-Liste

object

Rückgabewerte

Returns the aggregation information as an associative array of arrays of methods and properties. The key for the main array is the name of the aggregated class.

Beispiele

Beispiel #1 Using aggregate_info()

<?php

class Slicer {
    var 
$vegetable;

    function 
Slicer($vegetable
    {
        
$this->vegetable $vegetable;
    }

    function 
slice_it($num_cuts
    {
        echo 
"Doing some simple slicing\n";
        for (
$i=0$i $num_cuts$i++) {
            
// do some slicing
        
}
    }
}

class 
Dicer {
    var 
$vegetable;
    var 
$rotation_angle 90;   // degrees

    
function Dicer($vegetable
    {
        
$this->vegetable $vegetable;
    }

    function 
dice_it($num_cuts
    {
        echo 
"Cutting in one direction\n";
        for (
$i=0$i $num_cuts$i++) {
            
// do some cutting
        
}
        
$this->rotate($this->rotation_angle);
        echo 
"Cutting in a second direction\n";
        for (
$i=0$i $num_cuts$i++) {
            
// do some more cutting
        
}
    }

    function 
rotate($deg
    {
        echo 
"Now rotating {$this->vegetable} {$deg} degrees\n";
    }

    function 
_secret_super_dicing($num_cuts
    {
        
// so secret we cannot show you ;-)
    
}
}

$obj = new Slicer('onion');
aggregate($obj'Dicer');
print_r(aggregate_info($obj));
?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

Array
(
    [dicer] => Array
        (
            [methods] => Array
                (
                    [0] => dice_it
                    [1] => rotate
                )

            [properties] => Array
                (
                    [0] => rotation_angle
                )

        )

)
As you can see, all properties and methods of the Dicer class have been aggregated into our new object, with the exception of the class constructor and the method _secret_super_dicing()

Siehe auch


Keine BenutzerBeiträge.
- Beiträge aktualisieren...



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)