Reply to Re: Getting names of variables passed to functions...

Your name:

Reply:


Posted by Thomas Mlynarczyk on 10/13/07 12:15

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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация