php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #14092 Associative array,value in array can not be zero
Submitted: 2001-11-17 06:28 UTC Modified: 2001-11-17 06:48 UTC
From: prasek at silesia dot cz Assigned:
Status: Closed Package: Arrays related
PHP Version: 4.0.6 OS: linux RH7.0
Private report: No CVE-ID: None
 [2001-11-17 06:28 UTC] prasek at silesia dot cz
Associative arrays seems to be broken in some way.
it is impossible to use something like 

$variable["something"]=0;

example scripts:

A:

<?
	$userdata["user_star"]='10';
	$userdata["user_pohlavi"]="U";
	$userdata["user_count"]=1;	
	$userdata["user_vip"]="N";
	$userdata["user_lang"]="CZ";
	$userdata["user_tld"]="CZ";
	$userdata["user_fags"]="A";
	
	

show_values($userdata);


function show_values($pole)
	{
	echo "show";
	reset($pole);
	while(current($pole))
		{
		echo "index: ".key($pole)."  value: ".current($pole)."<br>";
		next($pole);
		}
	}

?>


Following script show proper results:

showindex: user_star value: 10
index: user_pohlavi value: U
index: user_count value: 1
index: user_vip value: N
index: user_lang value: CZ
index: user_tld value: CZ
index: user_fags value: A



But....


Script B:

<?
	$userdata["user_star"]='10';
	$userdata["user_pohlavi"]="U";
	$userdata["user_count"]=0;	
	$userdata["user_vip"]="N";
	$userdata["user_lang"]="CZ";
	$userdata["user_tld"]="CZ";
	$userdata["user_fags"]="A";
	
	

show_values($userdata);


function show_values($pole)
	{
	echo "show";
	reset($pole);
	while(current($pole))
		{
		echo "index: ".key($pole)."  value: ".current($pole)."<br>";
		next($pole);
		}
	}

?>

(only thig I change is : $userdata["user_count"]=0;	)




give INCORRECT result 



showindex: user_star value: 10
index: user_pohlavi value: U


..and rest of the array gone.....


PHP manual say that "A 'key' is either a nonnegative integer or a string...   ......A 'value' can be anything. ", so I thing I found bug...

My system: RedHat7.0cz , kernel 2.4.10+LIDS 1.0.16,output of PhpInfo() function :

PHP Version 4.0.6 
System Linux porky.devel.redhat.com 2.4.5-7smp #1 SMP Tue Jun 26 14:19:49 EDT 2001 i686 unknown 
Build Date Aug 27 2001 
Configure Command  './configure' 'i386-redhat-linux' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--prefix=/usr' '--with-config-file-path=/etc' '--disable-debug' '--enable-pic' '--disable-rpath' '--enable-inline-optimization' '--with-apxs=/usr/sbin/apxs' '--with-bz2' '--with-curl' '--with-db3' '--with-dom' '--with-exec-dir=/usr/bin' '--with-gd' '--with-gdbm' '--with-gettext' '--with-jpeg-dir=/usr' '--with-mm' '--with-openssl' '--with-png' '--with-regex=system' '--with-ttf' '--with-zlib' '--with-layout=GNU' '--enable-debugger' '--enable-ftp' '--enable-magic-quotes' '--enable-safe-mode' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-track-vars' '--enable-yp' '--enable-wddx' '--without-mysql' '--without-unixODBC' '--without-oracle' '--without-oci8' '--with-pspell' '--with-xml' 
Server API Apache 
Virtual Directory Support disabled 
Configuration File (php.ini) Path /etc/php.ini 
ZEND_DEBUG disabled 
Thread Safety disabled 

 This program makes use of the Zend scripting language engine:
Zend Engine v1.0.6, Copyright (c) 1998-2001 Zend Technologies

 


--------------------------------------------------------------------------------

PHP 4.0 Credits

--------------------------------------------------------------------------------

Configuration
PHP Core 
Directive Local Value Master Value 
allow_call_time_pass_reference
 On On 
allow_url_fopen
 1 1 
arg_separator.input
 & & 
arg_separator.output
 & & 
asp_tags
 Off Off 
auto_append_file
 no value no value 
auto_prepend_file
 no value no value 
browscap
 no value no value 
default_charset
 no value no value 
default_mimetype
 text/html text/html 
define_syslog_variables
 Off Off 
disable_functions
 no value no value 
display_errors
 On On 
display_startup_errors
 On On 
doc_root
 no value no value 
enable_dl
 On On 
error_append_string
 </font></h3> </font></h3> 
error_log
 no value no value 
error_prepend_string
 <h3><font color=ff0000> <h3><font color=ff0000> 
error_reporting
 2039 2039 
expose_php
 On On 
extension_dir
 /usr/lib/php4 /usr/lib/php4 
file_uploads
 1 1 
gpc_order
 GPC GPC 
highlight.bg
 #FFFFFF #FFFFFF 
highlight.comment
 #FF8000 #FF8000 
highlight.default
 #0000BB #0000BB 
highlight.html
 #000000 #000000 
highlight.keyword
 #007700 #007700 
highlight.string
 #DD0000 #DD0000 
html_errors
 On On 
ignore_user_abort
 Off Off 
implicit_flush
 Off Off 
include_path
 .:/usr/share/php .:/usr/share/php 
log_errors
 Off Off 
magic_quotes_gpc
 On On 
magic_quotes_runtime
 Off Off 
magic_quotes_sybase
 Off Off 
max_execution_time
 30 30 
open_basedir
 no value no value 
output_buffering
 Off Off 
output_handler
 no value no value 
post_max_size
 8M 8M 
precision
 14 14 
register_argc_argv
 On On 
register_globals
 On On 
safe_mode
 Off Off 
safe_mode_exec_dir
 no value no value 
sendmail_from
 me@localhost.com me@localhost.com 
sendmail_path
 /usr/sbin/sendmail -t -i  /usr/sbin/sendmail -t -i  
short_open_tag
 On On 
SMTP
 localhost localhost 
sql.safe_mode
 Off Off 
track_errors
 On On 
upload_max_filesize
 2M 2M 
upload_tmp_dir
 no value no value 
user_dir
 no value no value 
variables_order
 EGPCS EGPCS 
y2k_compliance
 Off Off 


yp
YP Support enabled 


xml
XML Support active 


wddx
WDDX Support enabled 


standard
Regex Library System library enabled 
Dynamic Library Support enabled 
Path to sendmail /usr/sbin/sendmail -t -i  

Directive Local Value Master Value 
assert.active
 1 1 
assert.bail
 0 0 
assert.callback
 no value no value 
assert.quiet_eval
 0 0 
assert.warning
 1 1 
safe_mode_allowed_env_vars
 PHP_ PHP_ 
safe_mode_protected_env_vars
 LD_LIBRARY_PATH LD_LIBRARY_PATH 
session.use_trans_sid
 1 1 


sockets
sockets support enabled 


session
Session Support enabled 

Directive Local Value Master Value 
session.auto_start
 Off Off 
session.cache_expire
 180 180 
session.cache_limiter
 nocache nocache 
session.cookie_domain
 no value no value 
session.cookie_lifetime
 0 0 
session.cookie_path
 / / 
session.cookie_secure
 Off Off 
session.entropy_file
 no value no value 
session.entropy_length
 0 0 
session.gc_maxlifetime
 1440 1440 
session.gc_probability
 1 1 
session.name
 PHPSESSID PHPSESSID 
session.referer_check
 no value no value 
session.save_handler
 files files 
session.save_path
 /tmp /tmp 
session.serialize_handler
 php php 
session.use_cookies
 On On 


pspell
PSpell Support enabled 


posix
Revision $Revision: 1.28.2.1 $ 


pcre
PCRE (Perl Compatible Regular Expressions) Support enabled 
PCRE Library Version 3.4 22-Aug-2000 


openssl
OpenSSL support enabled 
OpenSSL Version OpenSSL 0.9.6b [engine] 9 Jul 2001 


gettext
GNU GetText Support enabled 


gd
GD Support enabled 
GD Version 1.6.2 or higher 
JPG Support enabled 
PNG Support enabled 
WBMP Support enabled 


ftp
FTP support enabled 


domxml
DOM/XML enabled 
libxml Version 2.4.2 
XPath Support enabled 
XPointer Support enabled 


dba
DBA support enabled 
Supported handlers gdbm db3  


curl
CURL support enabled 
CURL Information libcurl 7.8 (OpenSSL 0.9.6b) (ipv6 enabled) 


bz2
BZip2 Support Enabled 
BZip2 Version 1.0.1, 23-June-2000 


zlib
ZLib Support enabled 
'zlib:' fopen wrapper enabled 
Compiled Version 1.1.3 
Linked Version 1.1.3 


pgsql
PostgreSQL Support enabled 
Active Persistent Links 0 
Active Links 0 

Directive Local Value Master Value 
pgsql.allow_persistent
 On On 
pgsql.max_links
 Unlimited Unlimited 
pgsql.max_persistent
 Unlimited Unlimited 


apache
APACHE_INCLUDE   
APACHE_TARGET   
Apache Version Apache/1.3.20 
Apache Release 10320100 
Apache API Version 19990320 
Hostname:Port www.ds-life.cz:80 
User/Group apache(48)/48 
Max Requests Per Child: 1000<br>Keep Alive: off<br>Max Per Connection: 100 
Timeouts Connection: 300<br>Keep-Alive: 15 
Server Root /etc/httpd 
Loaded Modules mod_put, mod_ssl, mod_dav, mod_php4, mod_perl, mod_setenvif, mod_so, mod_headers, mod_expires, mod_auth_db, mod_auth_anon, mod_auth, mod_access, mod_rewrite, mod_alias, mod_userdir, mod_actions, mod_imap, mod_asis, mod_cgi, mod_dir, mod_autoindex, mod_include, mod_info, mod_status, mod_negotiation, mod_mime, mod_log_referer, mod_log_agent, mod_log_config, mod_env, mod_throttle, mod_bandwidth, mod_vhost_alias, http_core 


Apache Environment
Variable Value 
DOCUMENT_ROOT /home/ds-life/web 
HTTP_ACCEPT image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, */* 
HTTP_ACCEPT_ENCODING gzip, deflate 
HTTP_ACCEPT_LANGUAGE cs 
HTTP_CONNECTION Keep-Alive 
HTTP_HOST www.ds-life.cz 
HTTP_USER_AGENT Mozilla/4.0 (compatible; MSIE 5.5; Windows 98) 
PATH /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin 
REMOTE_ADDR 213.235.189.16 
REMOTE_PORT 4023 
SCRIPT_FILENAME /home/ds-life/web/phpinfo.php 
SERVER_ADDR 213.235.189.14 
SERVER_ADMIN team@ds-life.cz 
SERVER_NAME www.ds-life.cz 
SERVER_PORT 80 
SERVER_SIGNATURE <ADDRESS>Apache/1.3.20 Server at www.ds-life.cz Port 80</ADDRESS>
 
SERVER_SOFTWARE Apache/1.3.20 (Unix)  (Red-Hat/Linux) mod_ssl/2.8.4 OpenSSL/0.9.6b DAV/1.0.2 PHP/4.0.6 mod_perl/1.24_01 mod_throttle/3.1.2 
GATEWAY_INTERFACE CGI/1.1 
SERVER_PROTOCOL HTTP/1.1 
REQUEST_METHOD GET 
QUERY_STRING   
REQUEST_URI /phpinfo.php 
SCRIPT_NAME /phpinfo.php 


HTTP Headers Information
HTTP Request Headers 
HTTP Request GET /phpinfo.php HTTP/1.1 
Accept image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, */* 
Accept-Encoding gzip, deflate 
Accept-Language cs 
Connection Keep-Alive 
Host www.ds-life.cz 
User-Agent Mozilla/4.0 (compatible; MSIE 5.5; Windows 98) 
HTTP Response Headers 
X-Powered-By PHP/4.0.6 
Connection close 
Transfer-Encoding chunked 
Content-Type text/html 


Additional Modules
sysvshm 
sysvsem 
Session MM 


Environment
Variable Value 
PWD / 
BOOT_FILE /boot/kernel-2.4.10-2 
HOSTNAME www.webpropag.cz 
CONSOLE /dev/console 
PREVLEVEL # 
AUTOBOOT YES 
runlevel 3 
MACHTYPE i386-redhat-linux-gnu 
SHLVL 2 
previous # 
BOOT_IMAGE k3 
SHELL /bin/bash 
HOSTTYPE i386 
OSTYPE linux-gnu 
HOME / 
TERM linux 
PATH /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin 
RUNLEVEL 3 
INIT_VERSION sysvinit-2.78 
_ /bin/nice 


PHP Variables
Variable Value 
PHP_SELF /phpinfo.php 
HTTP_SERVER_VARS["DOCUMENT_ROOT"] /home/ds-life/web  
HTTP_SERVER_VARS["HTTP_ACCEPT"] image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, */*  
HTTP_SERVER_VARS["HTTP_ACCEPT_ENCODING"] gzip, deflate  
HTTP_SERVER_VARS["HTTP_ACCEPT_LANGUAGE"] cs  
HTTP_SERVER_VARS["HTTP_CONNECTION"] Keep-Alive  
HTTP_SERVER_VARS["HTTP_HOST"] www.ds-life.cz  
HTTP_SERVER_VARS["HTTP_USER_AGENT"] Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)  
HTTP_SERVER_VARS["PATH"] /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin  
HTTP_SERVER_VARS["REMOTE_ADDR"] 213.235.189.16  
HTTP_SERVER_VARS["REMOTE_PORT"] 4023  
HTTP_SERVER_VARS["SCRIPT_FILENAME"] /home/ds-life/web/phpinfo.php  
HTTP_SERVER_VARS["SERVER_ADDR"] 213.235.189.14  
HTTP_SERVER_VARS["SERVER_ADMIN"] team@ds-life.cz  
HTTP_SERVER_VARS["SERVER_NAME"] www.ds-life.cz  
HTTP_SERVER_VARS["SERVER_PORT"] 80  
HTTP_SERVER_VARS["SERVER_SIGNATURE"] <ADDRESS>Apache/1.3.20 Server at www.ds-life.cz Port 80</ADDRESS>
  
HTTP_SERVER_VARS["SERVER_SOFTWARE"] Apache/1.3.20 (Unix)  (Red-Hat/Linux) mod_ssl/2.8.4 OpenSSL/0.9.6b DAV/1.0.2 PHP/4.0.6 mod_perl/1.24_01 mod_throttle/3.1.2  
HTTP_SERVER_VARS["GATEWAY_INTERFACE"] CGI/1.1  
HTTP_SERVER_VARS["SERVER_PROTOCOL"] HTTP/1.1  
HTTP_SERVER_VARS["REQUEST_METHOD"] GET  
HTTP_SERVER_VARS["QUERY_STRING"]   
HTTP_SERVER_VARS["REQUEST_URI"] /phpinfo.php  
HTTP_SERVER_VARS["SCRIPT_NAME"] /phpinfo.php  
HTTP_SERVER_VARS["PATH_TRANSLATED"] /home/ds-life/web/phpinfo.php  
HTTP_SERVER_VARS["PHP_SELF"] /phpinfo.php  
HTTP_SERVER_VARS["argv"] Array
(
)

  
HTTP_SERVER_VARS["argc"] 0  
HTTP_ENV_VARS["PWD"] /  
HTTP_ENV_VARS["BOOT_FILE"] /boot/kernel-2.4.10-2  
HTTP_ENV_VARS["HOSTNAME"] www.webpropag.cz  
HTTP_ENV_VARS["CONSOLE"] /dev/console  
HTTP_ENV_VARS["PREVLEVEL"] #  
HTTP_ENV_VARS["AUTOBOOT"] YES  
HTTP_ENV_VARS["runlevel"] 3  
HTTP_ENV_VARS["MACHTYPE"] i386-redhat-linux-gnu  
HTTP_ENV_VARS["SHLVL"] 2  
HTTP_ENV_VARS["previous"] #  
HTTP_ENV_VARS["BOOT_IMAGE"] k3  
HTTP_ENV_VARS["SHELL"] /bin/bash  
HTTP_ENV_VARS["HOSTTYPE"] i386  
HTTP_ENV_VARS["OSTYPE"] linux-gnu  
HTTP_ENV_VARS["HOME"] /  
HTTP_ENV_VARS["TERM"] linux  
HTTP_ENV_VARS["PATH"] /sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin  
HTTP_ENV_VARS["RUNLEVEL"] 3  
HTTP_ENV_VARS["INIT_VERSION"] sysvinit-2.78  
HTTP_ENV_VARS["_"] /bin/nice  





Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-11-17 06:32 UTC] derick@php.net
THis is expected behavior,

if current($pole) evaluates to 0, it's considered false as a while conditition:

while (current($pole)) {      <<<--->>> while (0) {

You want to use:

while (current($pole) !== FALSE) {
 [2001-11-17 06:44 UTC] hholzgra@php.net
or even better: use each() or foreach()
to traverse arrays

http://php.net/each
http://php.net/foreach
 [2001-11-17 06:48 UTC] prasek at silesia dot cz
I try even to use 

while (current($pole) != FALSE)
with the some (wrong) result.

but 
while (current($pole) !== FALSE)  works.

Thanx for help and sorry for the mess...

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 08 03:01:29 2024 UTC