php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #158 "Variable Variable" arrays don't work
Submitted: 1998-03-10 13:06 UTC Modified: 1998-03-10 13:21 UTC
Votes:2
Avg. Score:4.0 ± 1.0
Reproduced:1 of 1 (100.0%)
Same Version:2 (200.0%)
Same OS:1 (100.0%)
From: putsch at unitrode dot com Assigned: rasmus (profile)
Status: Closed Package: Other
PHP Version: 3.0b5 OS: Solaris 2.5.1
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: putsch at unitrode dot com
New email:
PHP Version: OS:

 

 [1998-03-10 13:06 UTC] putsch at unitrode dot com
Here's a script that demonstrates the problem. Note the output is
not correct:

<HTML>
  <HEAD>
    <TITLE>Tools Design Overview</TITLE>

  </HEAD>
  <BODY>
  <?php 
    $colDirs[] = "releasenotes";
    $colDirs[] = "devdatabook";
    $colDirs[] = "desrules";
    $colDirs[] = "techfiles";

    echo "<B>Setting:</b><br>";

    reset($colDirs);
    while($colDir = current($colDirs)) {

      for ($i=0; $i < 5; $i++) {
        printf ("%s[%d] to %d&nbsp;...;&nbsp;", $colDir, $i, $i);
        $$colDir[$i] = $i;
        printf ("%s[%d] = %d<br>", $colDir, $i, $$colDir[$i]);
      }

      next($colDirs);
    }

    echo "<B>Recalling:</b><br>";

    reset($colDirs);
    while($colDir = current($colDirs)) {

      for ($i=0; $i < 5; $i++) {
        printf ("%s[%d] = %d<br>", $colDir, $i, $$colDir[$i]);
      }

      next($colDirs);
    }
?>
</body>
</html>

configure was run as:

./configure  --with-apache=/local/src/WWW/apache_1.3b5 \
--with-mysql=/tools/mysql \
--with-config-file-path=/opt/WWW/etc \
--with-exec-dir=/opt/WWW/php-bin \
--enable-short-tags=no

This is my php3.ini file:

[PHP_3]
engine = 1  ; enable PHP 3.0 parser
 
max_execution_time = 30     ; Maximum execution time of each script, in seconds
memory_limit = 4194304          ; Maximum amount of memory a script may consume 
(4MB)
 
; error_reporting is a bit-field.  Add each number up to get desired error repor
ting level
;  1 = Normal errors
;  2 = Normal warnings
;  4 = Parser errors
;  8 = Really picky warnings - ie. using a variable before defining it
error_reporting=7
display_errors=1           ; Print out errors (as a part of the HTML script)
log_errors=0                       ; Log errors into a log file (server-specific
 log, stderr, or error_log (below))
track_errors=0             ; Store the last error/warning message in $php_errorm
sg (boolean)
;error_log=filename             ; log errors to specified file
;error_log=syslog               ; log errors to syslog (Event Log on NT, not val
id in Windows 95)
 
warn_plus_overloading=0         ; warn if the + operator is used with strings
 
magic_quotes_gpc = 1       ; magic quotes for incoming GET/POST/Cookie data
magic_quotes_runtime = 0   ; magic quotes for runtime-generated data, e.g. data 
from SQL, from exec(), etc.
magic_quotes_sybase = 0    ; Use Sybase-style magic quotes (escape ' with '' ins
tead of \')
track_vars=1               ; enable $PHP_GET_VARS[], $PHP_POST_VARS[] and $PHP_C
OOKIE_VARS[] arrays
short_open_tag=1           ; allow the <? tag.  otherwise, only <?php is recogni
zed.
 
; paths and directories
include_path=/opt/WWW/include
doc_root=/opt/WWW/httpd    ; the document root of the web server
user_dir=public_html          ; the directory under which the web server checks 
when using /~username
upload_tmp_dir=\windows\temp  ; temporary directory for HTTP uploaded files
extension_dir=./              ; directory in which the loadable extensions (modu
les) reside
 
 
; file extensions (meaningless in UNIX)

cgi_ext=php3
isapi_ext=php3
nsapi_ext=php3
 
 
; automatically add files before or after any PHP 3.0 document
auto_prepend_file=
auto_append_file=
 
 
[mail function]
SMTP=localhost                  ;for win32 only
sendmail_from=me@localhost.com  ;for win32 only
sendmail_path=                  ;for unix only
 
[safemode]
safe_mode=0
safe_mode_exec_dir=
 
[Debugger]
debugger.host=localhost
debugger.port=7869
debugger.enabled=0
 
[Logging]
logging=0
log_DBM=0
log_DBM_dir=.
log_SQL=0
 
[LoadExtensions]
; if you wish to have an extension loaded automaticly, use the
; following syntax:  extension=modulename.extension
; for example, on windows,
; extension=msql.dll
 
[Highlight]
; Colors for Syntax Highlighting mode.  Anything that's acceptable in <font colo
r=???> would work.
highlight.string        =       #DD0000
highlight.comment       =       #FF8000
highlight.keyword       =       #007700
highlight.bg            =       #FFFFFF
highlight.default       =       #0000BB
highlight.html          =       #000000
 
[SQL]
sql.safe_mode=0
 
[MySQL]
mysql.allow_persistent=1 ; allow or prevent persistent link
mysql.max_persistent=-1  ; maximum number of persistent links. -1 means no limit
mysql.max_links=-1       ; maximum number of links (persistent+non persistent). 
 -1 means no limit
 
[mSQL]
msql.allow_persistent=1 ; allow or prevent persistent link
msql.max_persistent=-1  ; maximum number of persistent links. -1 means no limit
msql.max_links=-1       ; maximum number of links (persistent+non persistent).  
-1 means no limit
 
[PostgresSQL]
pgsql.allow_persistent=1 ; allow or prevent persistent link
pgsql.max_persistent=-1  ; maximum number of persistent links. -1 means no limit
pgsql.max_links=-1       ; maximum number of links (persistent+non persistent). 
 -1 means no limit
 
[Sybase]
sybase.allow_persistent=1 ; allow or prevent persistent link
sybase.max_persistent=-1  ; maximum number of persistent links. -1 means no limi
t
sybase.max_links=-1       ; maximum number of links (persistent+non persistent).
  -1 means no limit
;sybase.interface_file = "/usr/sybase/interfaces"
sybase.min_error_severity=10   ; minimum error severity to display
sybase.min_message_severity=10 ; minimum message severity to display
 
 
[Sybase-CT]
sybct.allow_persistent=1 ; allow or prevent persistent link
sybct.max_persistent=-1  ; maximum number of persistent links. -1 means no limit
sybct.max_links=-1       ; maximum number of links (persistent+non persistent). 
 -1 means no limit
sybct.min_server_severity=10 ; minimum server message severity to display
sybct.min_client_severity=10 ; minimum client message severity to display
 
 
[bcmath]
bcmath.scale = 3    ; number of decimal digits for all bcmath functions
 
[browscap]
;browscap = extra/browscap.ini




Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1998-03-10 13:21 UTC] rasmus
This is not a bug.  The problem is that $$var[i] is ambiguos.

For example:  If you have $b[1]="c" and $a[1]="d" and $b="a"  $c="e";

What would  $$b[1] refer to?  $b[1] = c so $$b[1] could be $c which = "e"
Or $b = "c" so $$b = $c and $c[1] is undefined.  

You have to tell PHP what the index is dereferencing.  You need to use
either ${$b}[1] or ${$b[1]} depending on which variable you want the
array index to refer to.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 13:01:29 2024 UTC