Re: PHP and case-sensitivity inconsistency in PHP 6
On Sun, Jan 26, 2014 at 03:36:08PM -0800, Stas Malyshev wrote:
> Hi!
>
> > So essentially, I would like to see case sensitivity at call time
> > (called name must match declaration), but case insensitivity at
> > declaration time (when checking whether a symbol has already been
> > declared):
>
> What would function_exists('Foo') return when foo() is defined?
>
> If false, then this code:
>
> if (!function_exists('Foo')) {
> function Foo() { ... }
> }
>
> would not work. If true, then this code:
>
> if(function_exists('Foo')) {
> Foo();
> }
>
> would not work. Both are working fine now and there's no real reason why
> shouldn't they keep working.
>
> Additionally, making the engine case-sensitive would simplify some areas
> of function/class handling. But making it inconsistently partially
> case-sensitive would instead complicate it, as we now would have to make
> additional checks against original name before calling.
>
> My opinion is if we go case-sensitive, it must be full case sensitivity,
> no exceptions.
+1
We need to think about:
* there are a few special values that are currently case insenitive, eg: NULL, TRUE.
I would suggest that they only be recognised in upper case, eg: null would be
invalid. This fits with the meme of constant names being in upper case.
* transition, there must be a lot of code that has (accidental) case
inconsistencies in function/variable/... names. If PHP were not a dynamic
language (eg C) then this change would be caught at compile time. In PHP a case
inconsistency is only found when the code is executed. Programs can contain
blocks of code that are rarely executed - think: rare error recovery.
Something that would help with transition is the option to force variables to
be declared. If a variable is then used without being declared an error is raised.
We currently have the problem as illustrated below:
$foo = 'bar';
echo "foo=$f00";
With case insensitivity this problem will become worse.
What I propose is something like perl's 'use strict'. This causes a compilation
error if a variable is used that has not been defined. This pragma applies only
for the compilation module that it is in; ie it does not apply to 'include'd
files and so can be done on a module by module basis.
The way that I suggest that we do this is by using the existing keyword 'var'. Eg:
var $foo = 'bar';
or
var $foo;
If 'var' is seen in a module, then use of any variables below MUST be for
variables that have been declared.
OK: that is the general idea, details need working on.
Note that the use of 'var' to declare variables is OPTIONAL, only use it if you
want to.
--
Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer.
+44 (0) 787 668 0256 http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php
#include <std_disclaimer.h>
Thread (15 messages)