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
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: 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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 27 23:01:30 2024 UTC