Page 1 of 1

How to get an identity of a variable?

Posted: Mon Jun 09, 2003 6:52 am
by Dummkopf
I´d like to pass a variable by reference to a function, which is supposed to 'identify' the variable (perhaps by memory-location or something) and save the value and this identifier in an array.

Code: Select all

<?php

function logVar(& $var) {
   $id = getIdentifier($var) // ???
   if ( is_array($this->elements[$id]) ) { // identifier already exist
      $this->elements[$id][] = $var;
   } else {
      $this->elements[$id] = array($var);
   }
}

?>
Does anybody have any ideas ??

Posted: Mon Jun 09, 2003 10:02 am
by bradvan
I dont suppose that the compact() function will do what you want?

Posted: Mon Jun 09, 2003 10:59 am
by Dummkopf
No, it doesn't. ;)

I want to save the variable-name and it´s value only by giving the variable to the function by reference.

Then I can call that function, which is a member of a class, again and can save all different values the variable gets in the script.

The destructor prints all these variable-names and their different values.

Code: Select all

<?php
$L = new Log();

$var = "Hi";
$L->logVar($var);

$var .= " user!";
$L->logVar($var);
?>
Instead of

Code: Select all

<?php
$L = new Log();

$var = "Hi";
$L->logVar('var', $var);

$var .= " user!";
$L->logVar('var', $var);
?>