mardi 23 février 2016

How to use reflection to go from array to a data structure in php

I read on php.net that the SplFixedArray has "The advantage is that it allows a faster array implementation" over regular arrays. Some how I also want to understand reflection. I cannot seem to get it to work:

$refDLL = new ReflectionClass( 'SplDoublyLinkedList' );
$method = $refDLL->getMethod( 'add' );
$keys = array_keys( $_GET );
$count = count( $keys );
$oIndex = 0;
while( $oIndex < $count )
{
    $method( // <-- this seems to be the point of failure
        $oIndex, 
        $_GET[$keys[$oIndex]] 
    );
    $oIndex++;
}

error:

PHP Fatal error:  Uncaught Error: Function name must be a string in 
C:\inetpub\wwwroot\objstr.php:26
Stack trace:
#0 {main}
  thrown in C:\inetpub\wwwroot\objstr.php on line 26





Aucun commentaire:

Enregistrer un commentaire