php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #19867 extract function and null values
Submitted: 2002-10-11 11:20 UTC Modified: 2002-11-10 18:19 UTC
From: adamw at uscho dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 4.2.0 OS: Linux
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: adamw at uscho dot com
New email:
PHP Version: OS:

 

 [2002-10-11 11:20 UTC] adamw at uscho dot com
In earlier versions of PHP ... when looping through a set of database data, for example, and "extract"ing on each loop -- the extract function would overwrite the variable with the previous value, even if it was NULL.

I just recently switched servers that had a more recent version of PHP.  Now extract behaves differently.  On the next pass through, the variable is not overwritten if the new value is NULL.  This requires the use of "unset" on each loop for each variable that could have NULL values.

I see nothing in the changelog about this, so I'm trying to determine if it's a bug, or was changed on purpose.  If it's a change, I'm not sure I understand why, since it would seem to be much more useful to have it overwritten with the NULL value.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-12 02:30 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-latest.zip


And if the snapshot doesn't do what you expect, please add a short, self-contained example script here which shows the
possible bug clearly.
 
 [2002-10-16 21:38 UTC] adamw at uscho dot com
I cannot install the snapshot at this time. I don't have access to do that.  I'm waiting for the provider to upgrade to 4.2.3.  I've put in requests.  In the meantime, what I know is, the follow behaves differently between 4.0.6 and 4.2

$sql = "SELECT * FROM $table WHERE gdate=$ymd";
$result=mysql_query($sql);
while ($row=mysql_fetch_array($result))
{
  extract($row);
  print $score;
}

Pretty simple standard stuff.  I've been using snippets to that effect all over in the projects I do for a couple years, and never noticed this.

On the first pass, if $score = 20, it will print 20.

On the second pass, is $score = NULL in the DB, it will again print 20.

Previously, it would print "<blank>" - as I would expect it to.

Could this be a glitch, or change, in mysql_fetch_array() as opposed to extract()?
 [2002-11-10 18:19 UTC] sniper@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 12:01:27 2024 UTC