#31730 [NEW]: behaviour of count() with strings
| From: | tierra at ibaku dot net | Date: | Thu, 27 Jan 2005 21:05:38 +0000 |
| Subject: | #31730 [NEW]: behaviour of count() with strings | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-72954@lists.php.net to get a copy of this message | ||
From: tierra at ibaku dot net
Operating system: Linux 2.4.27
PHP version: 5.0.3
PHP Bug Type: Arrays related
Bug description: behaviour of count() with strings
Description:
------------
This may not be a bug, but I would assume with the change in PHP5 (from
PHP4) where character access in strings is now done using array operators
that count('anystring') would return the length of the string (being the
number of array items in the string). I don't see any official
documentation on the reasoning for moving to array access operators with
strings in PHP5, but I've seen a number of reports that it was for the
movement of treating strings as arrays.
tierra@ibaku tierra $ php -v
PHP 5.0.3 (cli) (built: Dec 21 2004 20:37:03)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v2.0.3, Copyright (c) 1998-2004 Zend Technologies
tierra@ibaku tierra $ php count.php
count('string') returns: 1
tierra@ibaku tierra $ uname -a
Linux ibaku 2.4.27-linode36-3um #1 Fri Oct 29 00:59:10 EDT 2004 i686 UML
User Mode Linux GNU/Linux
PHP Version => 5.0.3
System => Linux ibaku 2.4.27-linode36-3um #1 Fri Oct 29 00:59:10 EDT 2004
i686
Build Date => Dec 21 2004 20:26:48
Configure Command => './configure' '--prefix=/usr'
'--host=i686-pc-linux-gnu' '--mandir=/usr/share/man'
'--infodir=/usr/share/info' '--datadir=/usr/share' '--sysconfdir=/etc'
'--localstatedir=/var
/lib' '--disable-cgi' '--enable-cli' '--enable-embed'
'--with-config-file-path=/etc/php/cli-php5' '--disable-bcmath'
'--without-bz2' '--disable-calendar' '--without-cpdflib'
'--disable-ctype'
'--wi
th-curl' '--without-curlwrappers' '--disable-dbase'
'--disable-dio'
'--disable-exif' '--without-fam' '--without-fbsql'
'--without-fdftk'
'--disable-filepro' '--disable-ftp' '--with-gettext' '--with
out-gmp' '--without-hwapi' '--without-iconv' '--without-informix'
'--without-ingres' '--without-interbase' '--without-kerberos'
'--enable-mbstring' '--with-mcrypt' '--without-mcve'
'--disable-memor
y-limit' '--without-mhash' '--without-mime-magic'
'--without-ming'
'--without-mnogosearch' '--without-msql' '--without-mssql'
'--with-ncurses' '--without-oci8' '--without-oracle'
'--with-openssl' '
--with-openssl-dir=/usr' '--without-ovrimos' '--disable-pcntl'
'--without-pfpro' '--without-pgsql' '--disable-posix'
'--with-pspell'
'--without-recode' '--disable-shmop' '--without-snmp' '--disable
-soap' '--disable-sockets' '--disable-spl' '--without-sybase'
'--without-sybase-ct' '--disable-sysvmsg' '--disable-sysvsem'
'--disable-sysvshm' '--without-tidy' '--disable-tokenizer'
'--disable-wdd
x' '--with-xsl' '--with-xmlrpc' '--disable-yp'
'--with-zlib'
'--disable-debug' '--without-cdb' '--with-db4'
'--without-dbm'
'--without-flatfile' '--with-gdbm' '--without-inifile'
'--without-qdbm' '
--with-jpeg-dir=/usr' '--with-freetype-dir=/usr' '--with-t1lib=/usr'
'--with-ttf=/usr' '--enable-gd-jis-conf' '--enable-gd-native-ttf'
'--with-png-dir=/usr' '--with-tiff-dir=/usr' '--without-xpm-di
r' '--with-gd' '--with-imap' '--with-imap-ssl'
'--with-mysql'
'--with-mysql-sock=/var/run/mysqld/mysqld.sock' '--without-mm'
'--without-msession' '--enable-sqlite-utf8' '--enable-dba'
'--with-readl
ine' '--without-libedit'
Reproduce code:
---------------
<?php echo "count('string') returns: " . count('string') .
"\n"; ?>
Expected result:
----------------
count('string') returns: 6
Actual result:
--------------
count('string') returns: 1
--
Edit bug report at http://bugs.php.net/?id=31730&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=31730&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=31730&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=31730&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=31730&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=31730&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=31730&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=31730&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=31730&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=31730&r=support
Expected behavior: http://bugs.php.net/fix.php?id=31730&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=31730&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=31730&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=31730&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=31730&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=31730&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=31730&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=31730&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=31730&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=31730&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=31730&r=mysqlcfg