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

Your name:

Reply:


Posted by michael on 10/10/07 17:55

On Oct 10, 7:53 pm, mich...@greenquery.com wrote:
> On Oct 10, 2:00 pm, BoneIdol <leon...@hotmail.com> wrote:
>
>
>
> > Anyway to do it? I know you can use a variable's contents as a
> > variable name with $$name. With something like this:
>
> > <?php
> > function foo($bar)
> > {
> > return $bar;
> > }
>
> > $name = foo($variable_name);
> > ?>
>
> > I'd like the function foo to return a string of the variable name
> > passed to it, in this case 'variable_name'. A friend of mine who does
> > C ++ programming says that pointers are the way to go here,
> > but as far as I know PHP doesn't support them.
>
> Okay if you are using classes. Then this is dead on easy.
>
> <?php
>
> class MyClass {
> var $myname;
> var $myemail;
> var $myphonenr;
> function getVariable($var){ return $this->$var;}
> function setVariable($var,$value){ $this->$var = $value;}
> }
>
> // Example use;
> $myclass = new $MyClass();
>
> $myclass->setVaribale("myname","Michael");
> $myclass->setVaribale("myemail","mich...@greenquery.com");
>
> print "Hi " . $myclass->getVariable("myname");
>
> //View the class
> var_dump($myclass);
>
> ?>
>
> I hope this is what your looking for
>
> Best Regards
> Michael

// Sorry Just fixed my misspells!


Okay if you are using classes. Then this is dead on easy.

<?php

class MyClass {
var $myname;
var $myemail;
var $myphonenr;
function getVariable($var){ return $this->$var;}
function setVariable($var,$value){ $this->$var = $value;}
}

// Example use;
$myclass = new $MyClass();

$myclass->setVariable("myname","Michael");
$myclass->setVariable("myemail","mich...@greenquery.com");

print "Hi " . $myclass->getVariable("myname");

//View the class
var_dump($myclass);

?>

I hope this is what your looking for

Best Regards
Michael

[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

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