You are here: Re: Easy question, return variable name « PHP Programming Language « IT news, forums, messages
Re: Easy question, return variable name

Posted by Tom on 12/15/06 12:55

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

 

Navigation:

[Reply to this 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

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