Re: Easy question, return variable name



Here's why I needed this "bobo" function:

I'm currently upgrading a website to use DB_DataObjects instead of the
DB class. However, it's a process that will take almost a month
because of the large number of scripts needing the update. In
addition, I need to keep legacy support for the DB class while I'm
upgrading, without creating any additional unnecessary database
connections.

I don't know the actual answer to this, but I always assumed creating
an extension of the DB_DataObject (i.e. class DataObject_MyTable
extends DB_DataObject) would create a separate connection. To get
around this, I was using a rather ugly hack to use the existing
connection from the legacy DB object:

<?php
$DB = DB::connect($dsn, $options);
$_DB_DATAOBJECT['CONNECTIONS']['DB'] =& $DB;
?>

That $_DB_DATAOBJECT array is set in the PEAR class definition in
DB/DataObject.php thru $GLOBALS, and it stores the name of the DB
object as a key. I was trying to write a function that would create
new DB_DataObjects for all existing DB classes without having to define
each one manually.

I've since given up though... I rather enjoyed the bobo_the_clown
function though -- very clever!

Iván Sánchez Ortega wrote:
Tom wrote:

Sorry, I should have been more specific -- I need the actual name of
the variable itself, not its datatype. So, I need function that does
the following:

<?php

$myArray = array( );
$myVariable = "foobar";

echo some_function($myArray); // should echo "myArray"
echo some_function($myVariable); // should echo "myVariable"

?>

No can do. Please have a in-depth look at the PHP manual,
chapter "References to variables".

I'll try to show you the inability to know the *name* of a variable. And,
please, before replying, do RTFM.

<?php

$a = "foobar";
$b =& $a;
$c =& $a;
$d =& $a;

unset($a);

echo some_function($c); // WTF??

?>

Now, in your opinion, what should this return?? $b, $c and $d all point to
the same memory address, because of how references work. And the name $a,
which originated that memory address, does not exist. So, do we
return 'b', 'c' or 'd'??

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

Razón #10 : Niegas vivamente la existencia de miles de dioses adorados por
otras religiones, pero te invade la ira cuando alguien niega la existencia
del tuyo.
-- Una de las jocosas, pero no por eso menos ciertas, Diez señales de
que eres un fundamentalista

.



Relevant Pages

  • Re: [PHP] Download speed limit
    ... Hmm that apache module isn't quite what I need, it just accepts or refuse connections based on bandwidth usage, it does not throttle the connection. ... Subject: [PHP] Download speed limit ...
    (php.general)
  • Re: Server Express Animator/Oracle Issues
    ... I am in the process of upgrading from MF OC ... > error code 12540 from Oracle when the connection is attempted. ... > experimenting with the upgrade process - so this doesn't make any ... routines before it reaches the call to program B. I found that if I ...
    (comp.lang.cobol)
  • Re: How to avoid exposing connectstring?
    ... > I'm using a MySQL database from within some Perl and PHP cgi's. ... > To make the connection, I have to supply the username/password ...
    (comp.lang.php)
  • RE: [PHP] Closing a connection to browser without exiting the script
    ... Closing a connection to browser without exiting the ... I have a PHP page that displays a message, and then, performs a very ... what I would like is to be able to close the connection from ... the server-side, but without using the exitfunction, so my script ...
    (php.general)
  • Re: The myth of road building
    ... Ewloe (for connection to A55 expressway for access to the coastal ... a motorway going from somewhere on or near the north Wales coast to ... Upgrading the road along the west coast to a dual ...
    (uk.transport)