Re: [PHP-DEV] Suggestion: global variables being accessed in localscope

2007-02-15 Thread Richard Lynch
[Taking this back on-list, as it's my final answer.]

On Wed, February 14, 2007 5:30 pm, Christian Schneider wrote:
 Richard Lynch wrote:
 But the code that checks for E_NOTICE also has to be altered to check
 for E_STRICT...

 How many applications use error handlers. And how many of them rely
on a
 specific code being a specific level? Out of curiousity: I wouldn't
even
 know why someone would do something like that, perhaps you have a
good example.

 Anyway, that's a BC break I find worth doing but I'm fully aware
that you will disagree.

Anybody on shared hosting who wants to log their errors somewhere out
of the morass of system logs without dinking around with .htaccess is
going to use set_error_handler.

For that matter, if .htaccess is off, and you can't edit php.ini,
set_error_handler is just about your only option for reasonable error
handling.

I think you will find that a LOT of distributed applications use this
to avoid splatting PHP error messages out.  Or, at least, they should
be using it, as there's no other way without using something you can't
rely on if your code is widely distributed in unknown environments.

I know *I* have used it more than a few times.

Once you decide to use set_error_handler, of course you are going to
treat E_ERROR, E_NOTICE, E_USER_ERROR differently.  You want to just
halt your script for E_ERROR, but probably just tell yourself to fix
the buglet of an E_NOTICE.

You may even put them in separate logs, or perhaps even email yourself
E_ERROR, but only log E_NOTICE.

I *know* I have switch() statements on the error level in my error
handlers, and you are going to break them.

I can understand why the purist / anal-retentive camp wants
un-initiliazed varaibles as E_STRICT rather than E_NOTICE, but does it
really make that much difference?

And, honestly, there *ARE* bugs that can be introduced if somebody
makes a typo that results in using an unitialized variable.

Though the PHP auto-initialization to '' (or 0 or false or whatever is
suitable after type-juggling) works 99% of the time, imagine something
like this:

?php
  /* lots of code */
  $foo = 42;
  /* lots of code */
  if ($foo === 42) echo foo!;
?

Now imagine that somebody deletes all the lots of code and also
accidentally deletes the initialization.

The thing you believe should be E_STRICT is, in fact, an E_NOTICE
worthy issue.

Not only CAN this happen, it HAS happened to me, and the E_NOTICE made
it patently obvious what had happened as soon as I ran my tests.

Therefore, I believe the uninitialized variables should NOT be moved
to E_STRICT.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?



-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Suggestion: global variables being accessed in localscope

2007-02-10 Thread Richard Lynch
On Thu, February 8, 2007 7:43 pm, Christian Schneider wrote:
 Guilherme Blanco wrote:
 Brian,I am sorry about the message indentation... Seems
 PHP-Internals
 list does not like M$ Live(r) Mail!

 Please use plain text mail as your messages are a PITA to read,
 thanks.

Or very easy to read, as the spam filter just junks it...
:-v

 you can see, the only change needed is in a throw-able error
 (Undefined
 variable), which does a second look-up in the symbolTable.Doing
 this, you do not need to use $GLOBALS nevermore! And also, global
 can

 You didn't grasp two of the major PHP features (not bugs!):
 1. Every variable you access inside a function is local unless
 explicitely imported (through $GLOBALS, global or superglobals) from
 the
 global scope.

And that's the way it should be, unless you really like tracking down
obscure bugs from totally unrelated code messing with your variables.

 2. Accessing undefined variables is normal and not an error (not
 everybody agrees here but lots of people consider this a big plus).

Actually, it's not at all normal, and PHP throws an E_NOTICE.

It's your own fault if you haven't turned that on in your
error_reporting.

-- 
Some people have a gift link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Suggestion: global variables being accessed in localscope

2007-02-09 Thread Derick Rethans
On Fri, 9 Feb 2007, Guilherme Blanco wrote:

 Christian Schneider wrote:
  Please use plain text mail as your messages are a PITA to read, thanks.
 
 I changed the email to send/recieve messages. Hotmail simply doesn't
 accept plain text.

hotmail also fucks up threading :I

regards,
Derick

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Suggestion: global variables being accessed in localscope

2007-02-08 Thread Christian Schneider

Guilherme Blanco wrote:

Brian,I am sorry about the message indentation... Seems PHP-Internals
list does not like M$ Live(r) Mail!


Please use plain text mail as your messages are a PITA to read, thanks.



you can see, the only change needed is in a throw-able error (Undefined
variable), which does a second look-up in the symbolTable.Doing
this, you do not need to use $GLOBALS nevermore! And also, global can


You didn't grasp two of the major PHP features (not bugs!):
1. Every variable you access inside a function is local unless 
explicitely imported (through $GLOBALS, global or superglobals) from the 
global scope.
2. Accessing undefined variables is normal and not an error (not 
everybody agrees here but lots of people consider this a big plus).


Changing this would turn PHP into a completely different language so 
it's simply not going to happen. If you don't like these basic concepts 
it's probably a good idea to switch language.


Regards,
- Chris

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DEV] Suggestion: global variables being accessed in localscope

2007-02-08 Thread Guilherme Blanco

Christian Schneider wrote:

Please use plain text mail as your messages are a PITA to read, thanks.


I changed the email to send/recieve messages. Hotmail simply doesn't
accept plain text.



You didn't grasp two of the major PHP features (not bugs!):
1. Every variable you access inside a function is local unless
explicitely imported (through $GLOBALS, global or superglobals) from the
global scope.
2. Accessing undefined variables is normal and not an error (not
everybody agrees here but lots of people consider this a big plus).

Changing this would turn PHP into a completely different language so
it's simply not going to happen. If you don't like these basic concepts
it's probably a good idea to switch language.


First of all, I sleep with PHP codes printed everyday... I can't live
without PHP =D Forget about your suggestion to switch the
language!

Exactly. And I also commented it in my blog (Maybe this suggestion is
currently too much difficult to achieve.)... this is a drastic
change!
I suggested a similar change, that does the same thing. My suggestion:

Implement a register_superglobal function, that add the variable in a
HashTable... something like this (remember... Compiler class scope):

function register_superglobal( $varName ) {
   global $$varName;

   $this-symbolTable-registered_superg-hash[ $varName ] = $$varName;
}


And then... in your variable retrieval (I wrote the code in PHP now...
you scared me about that language switch!)... instead of the current
implementation (I removed the fatal error, based on your comment:
Accessing undefined variables is normal and not an error):

// Retrieve variable from local scope
$v = $this-symbolTable-getInLocal( $this-lexer-getStringValue() );

if ( $v === null ) {
   // ...
}


To something like this:

// Retrieve variable from local scope
$v = $this-symbolTable-getInLocal( $this-lexer-getStringValue() );

if ( $v === null ) {
   // Try to retrieve the variable from registered superglobal hash
   $v = $this-symbolTable-registered_superg-hash[
$this-lexer-getStringValue() ];

   if ( $v === null ) {
   // ...
   }
}


As you can see... just a little change, and now I do not change the
whole PHP behavior!
And I enabled the possibility to add the function I suggested. The
performance impact is minimal (almost 0).

If you do not accept my idea, I'll understand. I am just trying to
help PHP to be a better and language and also help lots of PHP
developer like to make code easier to write. =)


Best regards,

--
Guilherme Blanco - Web Developer
CBC - Certified Bindows Consultant
Cell Phone: +55 (16) 9166-6902
MSN: [EMAIL PROTECTED]
URL: http://blog.bisna.com
São Carlos - SP/Brazil