Afficher un message
Vieux 13/10/2007, 13h15   #3
Thomas Mlynarczyk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Getting names of variables passed to functions...

Also sprach BoneIdol:

> Anyway to do it?


No. You could try this (not tested, though):

$foo = 'bar';
doSomething( compact( 'foo' ) );

function doSomething( $aVar )
{
list( $sVarName, $xVarValue ) = each( $aVar );
echo "The variable is called $sVarName and has the value $xVarValue.\n";
}

With objects in PHP5 you can use the __set()/__get()/__call() magic
functions (not tested either):

class Foo
{
private $_aVars = array();

public function __set( $sName, $xValue )
{
echo "Setting $sName to value $xValue.\n";
$this->_aVars[$sName] = $xValue;
}

public function __get( $sName )
{
echo "Getting $sName.\n";
return $this->_aVars[$sName];
}
}

$oFoo = new Foo;
$oFoo->bar = 'baz';
echo $oFoo->bar;

But why do you need such a functionality? Maybe there is a solution to your
problem (whatever it is) which does not require it?

Greetings,
Thomas


  Réponse avec citation
 
Page generated in 0,05174 seconds with 9 queries