From:             kexianbin at diyism dot com
Operating system: Irrelevant
PHP version:      5.3.0RC2
PHP Bug Type:     Feature/Change Request
Bug description:  provide a function to get caller scope variables

Description:
------------
Provide a function to get variables from caller scope.

I knew ticket 47454, 40339, 34210 are similar,
but this is indeed a useful function that was overlooked.

Reproduce code:
---------------
Currently:

$name="myname";
$value="lk,jdsk'jlkjdf";
function safe($sql)
         {$sql=strtr($sql, array('"'=>'\"', '\\'=>'\\\\'));
          return 'return "'.preg_replace(array('/\{#(.*?)\}/'),
array('".addslashes($\1)."'), $sql).'";';
         }
$sql="insert into z_test (name, value) values ('{$name}', '{#value}')";
mysql_query(eval(safe($sql)));

If we have function get_caller_vars() in caller's scope:
(similar to get_defined_vars() in current scope)

$name="myname";
$value="lk,jdsk'jlkjdf";
function mysql_query_safe($sql)
         {extract(get_caller_vars());
          $sql=strtr($sql, array('"'=>'\"', '\\'=>'\\\\'));
          return 'return "'.preg_replace(array('/\{#(.*?)\}/'),
array('".addslashes($\1)."'), $sql).'";';
          $sql=eval($sql);
          mysql_query($sql);
         }
$sql="insert into z_test (name, value) values ('{$name}', '{#value}')";
mysql_query_safe($sql);

Expected result:
----------------
We have a function to get variables in caller scope.

Actual result:
--------------
No such function.

-- 
Edit bug report at http://bugs.php.net/?id=48290&edit=1
-- 
Try a CVS snapshot (PHP 5.2):        
http://bugs.php.net/fix.php?id=48290&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):        
http://bugs.php.net/fix.php?id=48290&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):        
http://bugs.php.net/fix.php?id=48290&r=trysnapshot60
Fixed in CVS:                        
http://bugs.php.net/fix.php?id=48290&r=fixedcvs
Fixed in CVS and need be documented: 
http://bugs.php.net/fix.php?id=48290&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=48290&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=48290&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=48290&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=48290&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=48290&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=48290&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=48290&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=48290&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=48290&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=48290&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=48290&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=48290&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=48290&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=48290&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=48290&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=48290&r=mysqlcfg

Reply via email to