php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #39091 Need to force variables to be declared
Submitted: 2006-10-09 10:40 UTC Modified: 2017-01-29 04:22 UTC
Votes:28
Avg. Score:4.5 ± 1.1
Reproduced:25 of 27 (92.6%)
Same Version:14 (56.0%)
Same OS:19 (76.0%)
From: addw at phcomp dot co dot uk Assigned:
Status: No Feedback Package: *General Issues
PHP Version: 5.2.0RC5 OS: any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2006-10-09 10:40 UTC] addw at phcomp dot co dot uk
Description:
------------
Could we not use 'var' to declare variables outside of functions and have a config option or file related pragma that made not declaring a variable an error ?

Yes: there would be a problem with existing code, so why not force variable declaration iff/after a 'var' declaration is seen.

If you really want to do it properly, then we could use 'private' or 'static' to declare variables with the scope of the file that they are declared in (like in C).

The most recent bug reference that I can find for this is: 14285 (Nov 2001).

This is a MUST HAVE, it is the single most dangerous mis-feature of PHP. Don't get me wrong - I like PHP, but just hanker after perl's use strict - great at pointing out typeos.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-11 19:08 UTC] ceo at l-i-e dot com
Turn error_reporting to E_ALL, and you have exactly what you asked for, and so much more.
 [2006-10-12 10:34 UTC] addw at phcomp dot co dot uk
No, E_ALL does not do everything that I need. It will not report mistyped variables who are assigned, only those that are used. E_ALL only generates a warning when code is executed which is not useful for infrequently executed code.
 [2017-01-20 21:58 UTC] heiglandreas@php.net
-Status: Open +Status: Feedback -Package: Feature/Change Request +Package: *General Issues
 [2017-01-20 21:58 UTC] heiglandreas@php.net
Is this still relevant?
 [2017-01-29 04:22 UTC] php-bugs at lists dot php dot 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 "Re-Opened". Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 07:01:27 2024 UTC