php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #27452 0 typed to NULL causes indexing error
Submitted: 2004-03-01 17:38 UTC Modified: 2004-03-01 17:59 UTC
From: Er1c at comcast dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.0b4 (beta4) OS: WinXP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: Er1c at comcast dot net
New email:
PHP Version: OS:

 

 [2004-03-01 17:38 UTC] Er1c at comcast dot net
Description:
------------
When a variable's type is "NULL" (as reported by var_dump()) which happens when the variable is set to 0, it can no longer be used to access the 0th position in an array.

In my perticular case, I was attempting this operation:
return $this->serverdata[$this->dataindex][$var];

and needed to do this to get it to run correctly:
return $this->serverdata[intval($this->dataindex)][$var];

I have not throughly tested this bug for other cases where it occurs, but this is definatly one of the cases.

Reproduce code:
---------------
class testing {
  private $dataindex;
  private $serverdata;

  function __construct() {
    $dataindex = 0;
    $serverdata = array(array("name"=>"Er1c","data"=>"foo"),array("name"=>"Bob","data"=>"bar"));
  }
  function __get($var) {
    return $this->serverdata[$this->dataindex][$var];
  }
}
$blah = new testing();
echo "Name:" . $blah->name;

Expected result:
----------------
Name: Er1c

Actual result:
--------------
Name:

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-01 17:59 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

You need to set the variables with $this-> too in your constructor.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Aug 01 01:00:02 2025 UTC