php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #45936 Appending undeclared array should generate a notice
Submitted: 2008-08-27 15:30 UTC Modified: 2008-08-28 06:24 UTC
From: php at bouchery dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.6 OS: All
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: php at bouchery dot com
New email:
PHP Version: OS:

 

 [2008-08-27 15:30 UTC] php at bouchery dot com
Description:
------------
When error_reporting is set to "E_ALL" and trying append an undeclared array, PHP should generate a "NOTICE" error.

Reproduce code:
---------------
<?php
error_reporting(E_ALL);

$array[] = 'string';

?> 

Expected result:
----------------
Notice: Undefined variable: array in /var/www/script.php on line 4

Actual result:
--------------
no error.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-27 18:10 UTC] tularis@php.net
why?

You assign a new array (and its first value) to a variable. What's wrong with that? 
If you see $array[] this as:
$array = array('string');
would you expect it to fire an E_NOTICE ?

no ?
then why would this do so, if it has 100% the same meaning.
 [2008-08-28 06:24 UTC] php at bouchery dot com
To my point of view, "[]" is like an operator which mean "append the array", but this variable is not declared.

In addition:
<?php
$x = 5;
$x[] = 7;
?>

This code will generate a "Warning: Cannot use a scalar value as an array".

It's not possible to do that because the variable is not an array and it show that the brackets are a kind of operator, not a simple assignment.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 15:01:34 2025 UTC