php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26054 using unreferenced variables does not produce errors
Submitted: 2003-10-31 07:26 UTC Modified: 2003-10-31 07:54 UTC
From: sascha dot wildgrube at steganos dot com Assigned:
Status: Not a bug Package: *Programming Data Structures
PHP Version: 4.3.2 OS: all
Private report: No CVE-ID: None
 [2003-10-31 07:26 UTC] sascha dot wildgrube at steganos dot com
Description:
------------
Any variable identifier can be used in a statement - even if it hasn't been referenced before - without producing an error.

Most of the time when debuggong php code is spent for searching typos in variable names.

I consider it a bug that php does not produce and display error if it encounters an unreferenced variable in a statement.

A solution could be a "strict" statement. That tells php to throw errors in that case to stay backward compatible.

An even better solution would be the need to 

Reproduce code:
---------------
$nValue1 = 10;
$nValue2 = 20;
print($nVale1 + $nValue2);

Expected result:
----------------
Expected:

30

No, it is:

20

Why, because of the typo in line 3. What I want to happen in that case is this:

Parse error: parse error in /somefile.php4 on line 3: unreferenced object "$nVale1"

Actual result:
--------------
20

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-31 07:37 UTC] sascha dot wildgrube at steganos dot com
An even better solution would be the need to initialize variables like that "var $nValue;". This way even typos in  in lvalues would not do any harm.

We once observed how much percent of the time was consumed by this bug. We found out that 30% of the time when working on php code could be saved if php had strict variable usage.
 [2003-10-31 07:54 UTC] alan_k@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

try error_reporting(E_ALL);


 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Oct 29 09:02:33 2020 UTC