Home » Database » DB » Bug #4868
PHP4.4 Only variable references should be returned by reference
Details
| Submitted | 2005-07-20 06:06 UTC |
|---|---|
| From | sumeet at prateeksha dot com |
| Assigned | danielc |
| Status | Bogus |
| Package | DB |
| PHP Version | 4.4.0 |
| OS | linux |
| Roadmaps | (Not assigned) |
Comments
[2005-07-20 06:06 UTC] sumeet at prateeksha dot com
Description:
------------
dear sir,
my server adminstrator in his infinite wisdom, has recently upgrade to PHP version 4.4. the DB pear library give me the following error.
Error No. 8 in Line No. 1127 in File : /home/public_html/DB.php
Only variable references should be returned by reference
Please can anybody rectify the same..
sumeet shroff
Reproduce code:
---------------
function &fetchRow($fetchmode = DB_FETCHMODE_DEFAULT, $rownum = null)
{
if ($fetchmode === DB_FETCHMODE_DEFAULT) {
$fetchmode = $this->fetchmode;
}
if ($fetchmode === DB_FETCHMODE_OBJECT) {
$fetchmode = DB_FETCHMODE_ASSOC;
$object_class = $this->fetchmode_object_class;
}
if ($this->limit_from !== null) {
if ($this->row_counter === null) {
$this->row_counter = $this->limit_from;
// Skip rows
if ($this->dbh->features['limit'] === false) {
$i = 0;
while ($i++ < $this->limit_from) {
$this->dbh->fetchInto($this->result, $arr, $fetchmode);
}
}
}
if ($this->row_counter >= ($this->limit_from + $this->limit_count))
{
if ($this->autofree) {
$this->free();
}
$tmp = null;
return $tmp;
}
if ($this->dbh->features['limit'] === 'emulate') {
$rownum = $this->row_counter;
}
$this->row_counter++;
}
$res = $this->dbh->fetchInto($this->result, $arr, $fetchmode, $rownum);
if ($res === DB_OK) {
if (isset($object_class)) {
// The default mode is specified in the
// DB_common::fetchmode_object_class property
if ($object_class == 'stdClass') {
$arr = (object) $arr;
} else {
$arr = &new $object_class($arr);
}
}
return $arr; // line 1127
}
Actual result:
--------------
Error No. 8 in Line No. 1127 in File : /home/public_html/DB.php
Only variable references should be returned by reference
[2005-07-20 07:46 UTC] sumeet at prateeksha dot com
hello friends
i have earlier posted this bug, and since then found a solution.
line 1127 should read as
$arr2 = $arr;
return $arr2;
instead of
return $arr;
Sumeet Shroff
[2005-07-21 05:59 UTC] sumeet at prateeksha dot com
dear danielc,
thanks for your input. i cannot pinpoint the "test code" but it is when i use $result->fetchRow(DB_FETCHMODE_ASSOC).
I have a win32 local machine, and the problem does not occur on my local macine, but my server is linux and i now need to conduct the test there.
one of the major changes (see changelog) for php 4.4.0 is "Fixed memory corruptions when using references in a wrong way."
maybe that has something to do with the error that i recieve.
sumeet shroff
[2005-07-21 17:14 UTC] sumeet at prateeksha dot com
dear danielc
i am using php 4.40 on the server and the mysql is version 4.1.11 .
the problem is that i have used several classes using the DB and HTML_Template PEAR library, hence it is difficult to pinpoint the code. unless i reproduce the entire classes.
but what i am surprised is that i just changed line 1127 and it works.
sumeet
[2005-07-26 11:30 UTC] h dot sintemaartensdijk at apx dot nl
Please reopen this issue, as it is not bogus. I had the same issue and managed to create a fairly simple script to reproduce this behaviour.
I'm running php 4.4.0 on win32
<?php
error_reporting(E_ALL);
require_once 'DB.php';
$dsn = 'oci8://web:web@APXDAMELTEST2';
$options = array(
'debug' => 2,
'portability' => DB_PORTABILITY_ALL,
);
$db =& DB::connect($dsn, $options);
if (PEAR::isError($db)) {
die($db->getMessage());
}
$sql = 'SELECT * FROM mytable;
$rows = $db->getAll($sql, DB_FETCHMODE_ASSOC);
?>
The resulting error is
Notice: Only variable references should be returned by reference in d:\PHP4\PEAR\DB\common.php on line 1633
This is a different line than the one original error, since I use getAll rather than fetchRow, but it should be related.
I noticed the error only shows if I specify a fetchmode in the getAll, that should help find the cause.
[2005-07-27 17:18 UTC] sumeet at prateeksha dot com
dear sir,
i am now reproducing the code...
Reprocude code
--------------
$search_str = ' SELECT *, date_format(jobs_date,"%d-%m-%Y") as jobs_date_dmy FROM '.TABLE_JOBS.' tj
LEFT JOIN '.TABLE_JOBS_DESCRIPTION.' tjd
ON tj.jobs_id = tjd.jobs_id
WHERE 1 ';
$search_str .= ' ORDER BY jobs_sortorder';
global $connection;
$result = $connection->query($search_str);
$template = new cms_template();
$template->addBlockFile('PAGEBODY','PageBody','contents/search_for_jobs_listing.tpl.php');
if ( $result->numRows() > 0 ) {
while( $row = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
$template->setCurrentBlock('ROW');
foreach( $row as $key => $value ) {
$template->setVariable($key,$value);
}
$template->parseCurrentBlock();
}
}
else {
// <!-- BEGIN NOROW -->
$template->setCurrentBlock('NOROW');
$template->setVariable('DUMMY2','');
$template->parseCurrentBlock();
}
$template->show();
die;
------------------------
the is error is
Error No. 8 in Line No. 1127 in File : /home/chamber/public_html/DB.php
Only variable references should be returned by reference
sumeet shroff
[2005-07-28 05:02 UTC] sumeet at prateeksha dot com
dear danielc,
thanks you for your advice regarding reproducing code. i will keep that in mind next time.
as i mentioned that my server is using linux, php 4.4.0 and apache, the script does not work on my server.
we request you to kindly try the same on a linux box (hope u encoutner the error) and suggest a possible solution for the same.
your help is most appreciated.
sumeet
[2005-07-29 16:05 UTC] steve at overlee dot com
I am also on a Linux server and receiving the same error.
My error reads:
In /usr/lib/php/DB.php, line: 898
Only variable references should be returned by reference
This happened when the server was upgraded to PHP 4.4.0
I'm not even sure what triggers the error :s
[2005-08-01 21:03 UTC] steve at overlee dot com
Commenting out the following lines ignores the error:
//error_reporting (E_ALL ^ E_NOTICE);
//set_error_handler ('php_error_handler');
This is a temporary fix, it worked for me.
[2005-08-04 04:47 UTC] steve at overlee dot com
Here is the results (auto_prepend_file value is blank)
---------- Ver:4.4.0 SAPI:apache
---------- System: Linux virginia.networkphantom.net 2.4.21-27.0.2.ELsmp #1 SMP Wed Jan 12 23:35:44 EST 2005 i686
Configure Command: './configure' '--with-apxs=/usr/local/apache/bin/apxs' '--with-mysql' '--enable-magic-quotes' '--with-openssl' '--with-pear' '--enable-sockets' '--enable-track-vars' '--enable-versioning' '--with-curl' '--with-gettext' '--with-xml' '--with-dom' '--with-mcrypt' '--with-gd' '--with-iconv' '--enable-mbstring' '--with-mbstring=all' '--with-png-dir=/usr' '--with-jpeg-dir=/usr/local' '--with-zlib' '--with-kerberos' '--enable-bcmath' '--enable-calendar' '--with-xpm-dir=/usr/X11R6' '--enable-ftp' '--with-dom-xslt' '--with-imap' '--with-imap-ssl' '--with-mcrypt' '--with-mhash' '--with-mysqli' '--enable-discard-path' '--with-pdflib' '--enable-xslt' '--with-xslt-sablot' '--with-ttf' '--with-freetype-dir=/usr' '--enable-gd-native-ttf' '--enable-wddx' '--with-mssql' '--with-iconv'
Server API: Apache
auto_prepend_file: no value
Notice: Only variable references should be returned by reference in /usr/lib/php/DB/common.php on line 1605
Array ( [0] => Array ( [a] => 5 ) )
[2005-08-05 22:06 UTC] stevec at engr dot orst dot edu
PHP: 4.4.0
Pear DB: 1.7.6
Apache: 1.3.33 (running on linux)
What I've noticed is the error only occurs after it's read the last record in the record set. Maybe something with the EOF not setting correctly? Here is a simple script that reproduces the problem:
$rs = $dbh->query("SELECT * FROM `table`");
// If zero records, this errors
$row = $rs->fetchRow();
// This errors after the last record has been displayed
while ($row = $rs->fetchRow()) {
print_r($row);
}
[2005-08-16 14:54 UTC] cvs-php-net at schirmeier dot com
I get this error in another line of common.php:
Notice: Only variable references should be returned by reference in /var/www/localhost/..../libs/DB/common.php on line 766
As reported by others, this showed up after an upgrade to PHP 4.4.0. At least the notice in common.php:766 seems to be related to http://bugs.php.net/bug.php?id=33558 which is fixed in CVS and will vanish in PHP 4.4.1.
[2005-09-18 22:24 UTC] cvs-php-net at schirmeier dot com
Err. No idea what I was thinking when commenting this bug report.
Moving to current stable DB-1.7.6 solved the problem, it seems to have already been fixed in common.php v1.27 (resolving bug #361). Unfortunately I can't tell which DB version I was using before as it is under my own version control and there are no version hints besides the CVS $Id$ string...
Sorry for bothering you.
[2005-10-21 03:55 UTC] paul dot koch at gmx dot de
dear danielc,
thanks for your efforts.
I used your script and was able to reproduce the bug (PHP 4.40 with DB.php: 1.80 and common.php 1.137).
Then I tried your friendly suggestions from "2005-09-17 17:03 UTC".
I added the Array-Definition-Line above Line 1116. :-) (looked senseful).
But then I searched for common.php v 1.138 with no chance to find it. So this bug 's still working :-(
Any chance to get v 1.138 ???
Greetz&Thanks, Paul
[2005-10-21 23:50 UTC] paul dot koch at gmx dot de
Daniel,
thanks for your answer, i found and replaced the common.php to v1.138.
Unfortunately the notice-message still appears.
This ist the output of your script:
---------- Ver:4.4.0 SAPI:apache
---------- System: Linux webelch 2.6.10-as7-he.piii.4gb #1 SMP Thu Jun 2 10:12:05 CEST 2005 i686
Configure Command: './configure' '--program-prefix=php4-' '--prefix=/usr/local/php4' '--datadir=/usr/share/php4' '--with-config-file-path=/etc' '--enable-force-cgi-redirect' '--disable-debug' '--enable-pic' '--disable-rpath' '--enable-inline-optimization' '--with-bz2=shared' '--with-dom=shared,/usr' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--with-gd=shared' '--enable-gd-native-ttf' '--with-ttf=shared' '--with-gdbm=shared' '--with-gettext=shared' '--with-iconv=shared' '--with-jpeg-dir=shared,/usr' '--with-openssl' '--with-png=shared' '--with-pspell=shared' '--with-regex=system' '--with-xml=shared' '--with-expat=shared' '--with-zlib=/usr/local' '--with-zlib-dir=/usr/local' '--with-layout=GNU' '--enable-bcmath=shared' '--enable-exif=shared' '--enable-ftp=shared' '--enable-magic-quotes' '--enable-safe-mode' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-discard-path' '--enable-track-vars' '--enable-trans-sid' '--enable-yp' '--enable-wddx' '--without-oci8' '--with-pear=/usr/share/pear' '--with-imap=shared' '--with-imap-ssl' '--with-kerberos' '--with-ldap=shared' '--with-mysql=shared,/usr' '--enable-memory-limit' '--enable-shmop' '--enable-versioning' '--enable-calendar=shared' '--enable-dbx=shared' '--enable-dio=shared' '--enable-mcal=shared' '--enable-dba=shared' '--enable-dbase=shared' '--with-ndbm=shared' '--with-ndb=shared' '--with-mcrypt=shared' '--with-mhash=shared' '--with-ming=shared' '--with-curl=shared,/usr' '--with-apxs=/usr/local/apache/bin/apxs' '--enable-mbstring=shared'
Server API: Apache
auto_prepend_file: no value
Notice: Only variable references should be returned by reference in /usr/share/pear/DB/common.php on line 1633
Array ( [0] => Array ( [a] => 5 ) )
Notice: Only variable references should be returned by reference in /usr/share/pear/DB/common.php on line 1164
Regards, Paul
[2005-10-22 00:10 UTC] paul dot koch at gmx dot de
Daniel,
i forgot to change the include_path on top of your script.
So the above output of your script results by using DB.php and common.php of my service providers PEAR-Package, and I'm unable to identify the version of DB.php there, and sure there is no added line 1116.
Now i changed the include_path to the altered files DB.php and common.php, so here ist the output of your proposed replacement procedure:
---------- Ver:4.4.0 SAPI:apache
---------- System: Linux webelch 2.6.10-as7-he.piii.4gb #1 SMP Thu Jun 2 10:12:05 CEST 2005 i686
Configure Command: './configure' '--program-prefix=php4-' '--prefix=/usr/local/php4' '--datadir=/usr/share/php4' '--with-config-file-path=/etc' '--enable-force-cgi-redirect' '--disable-debug' '--enable-pic' '--disable-rpath' '--enable-inline-optimization' '--with-bz2=shared' '--with-dom=shared,/usr' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--with-gd=shared' '--enable-gd-native-ttf' '--with-ttf=shared' '--with-gdbm=shared' '--with-gettext=shared' '--with-iconv=shared' '--with-jpeg-dir=shared,/usr' '--with-openssl' '--with-png=shared' '--with-pspell=shared' '--with-regex=system' '--with-xml=shared' '--with-expat=shared' '--with-zlib=/usr/local' '--with-zlib-dir=/usr/local' '--with-layout=GNU' '--enable-bcmath=shared' '--enable-exif=shared' '--enable-ftp=shared' '--enable-magic-quotes' '--enable-safe-mode' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-discard-path' '--enable-track-vars' '--enable-trans-sid' '--enable-yp' '--enable-wddx' '--without-oci8' '--with-pear=/usr/share/pear' '--with-imap=shared' '--with-imap-ssl' '--with-kerberos' '--with-ldap=shared' '--with-mysql=shared,/usr' '--enable-memory-limit' '--enable-shmop' '--enable-versioning' '--enable-calendar=shared' '--enable-dbx=shared' '--enable-dio=shared' '--enable-mcal=shared' '--enable-dba=shared' '--enable-dbase=shared' '--with-ndbm=shared' '--with-ndb=shared' '--with-mcrypt=shared' '--with-mhash=shared' '--with-ming=shared' '--with-curl=shared,/usr' '--with-apxs=/usr/local/apache/bin/apxs' '--enable-mbstring=shared'
Server API: Apache
auto_prepend_file: no value
Notice: Only variable references should be returned by reference in /is/htdocs/11499/www.blablabla.de/includes/PEAR/DB/common.php on line 1638
Array ( [0] => Array ( [a] => 5 ) )
Notice: Only variable references should be returned by reference in /is/htdocs/11499/www.blablabla.de/includes/PEAR/DB/common.php on line 1169
[2005-10-25 09:52 UTC] tsidwick at gmail dot com
in the hope that someone finds this information usefull :
I just upgraded to php 4.4.0 on a debian sid server and received the same notice in several places within a medium sized framework (heavily dependant on pear)
however as a temporary patch as previously mentioned replacing :
return xxx;
with
$a = xxx;
return xxx;
makes the notice disapear.
the weirdest was DataObject.php (version 1.7.7) line 2583 which gave the notice with
return false;
but not with
$a = false;
return $a;
which to me points the finger directly at php, this code is too simple to contain an error.
[2006-10-10 19:13 UTC] gherson at snet dot net
Just to confirm problem and fix still apropos: I also made all of my many "Only variable references should be returned by reference" errors disappear by commenting out a simple
//return $result; in favor of:
$workaround=$result;
return $workaround;
The error first appeared on my site with upgrade to PHP5 on 1/24/06. Surprised to still see the problem with Zend Core for Oracle 1.5.0 (PHP Version 5.1.6, Zend Engine Version 2.1.0, Server API apache2handler).