php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31265 strange behaviour of array_keys function
Submitted: 2004-12-23 07:07 UTC Modified: 2004-12-29 18:36 UTC
From: dmitry dot bezer at enterra-inc dot com Assigned:
Status: No Feedback Package: Scripting Engine problem
PHP Version: 4.3.10 OS: Windows XP
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2004-12-23 07:07 UTC] dmitry dot bezer at enterra-inc dot com
Description:
------------
After setting up PHP4.3.10 my application stoped working with error message saying about error in one of PEAR files. 
After looking into code that caused error I figured out a very strange thing: the array_keys function gets as  parameter a valid array but returns NULL. I tried to reproduce the bug without using PEAR files but didn't succeed. So I will describe the issue using PEAR code.
File: PEAR/DB/dataobject.php (version 1.7.2) (DB_DataObject PEAR package)

P.S. I have no Zend debuger/optimizer/.... or any 3rd party extensions installed
php -v result:
C:\wwwroot\bug>php -v
PHP 4.3.10 (cgi-fcgi) (built: Dec 14 2004 17:47:59)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies


Reproduce code:
---------------
795     if (is_object($from)) {
796        $table = $from->__table;
797        $from = array_keys($from->table());
798     }
$from->table() returns a valid array , but $from after assignment becomes NULL. 
If we modidfy the code in the following way:
795     if (is_object($from)) {
796        $table = $from->__table;
           $tmp = $from->table();
           var_dump($tmp);
797        $from = array_keys($tmp);
           var_dump($from)
           die('theend');
798     }
the result will be:
array(2) {
  ["id"]=>
  int(129)
  ["name"]=>
  int(2)
}
NULL
theend

moreover if we modify the code in another way:
      if (is_object($from)) {
         $table = $from->__table;
         $tmp = $from->table();
         $from = null;
         $from = array_keys($tmp);
      }
PHP crashes and Windows offers to send a report to Bill Gates :)



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-23 10:57 UTC] derick@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try avoid embedding huge scripts into the report.
 [2004-12-29 18:36 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


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