Edit report at http://bugs.php.net/bug.php?id=52426&edit=1

 ID:                 52426
 User updated by:    gphemsley at gmail dot com
 Reported by:        gphemsley at gmail dot com
 Summary:            switch() does not issue PHP Notice for uninitialized
                     variable
 Status:             Bogus
 Type:               Bug
 Package:            Scripting Engine problem
 PHP Version:        5.2.14
 Block user comment: N

 New Comment:

That seems counter-intuitive to me, to just ignore code like that.
(Obviously, if I write "switch", I intend there to be a switch.)



I assume the portion of the documentation you're referring to (in your
canned message) is this:

"In the beginning, no code is executed. Only when a case statement is
found with a value that matches the value of the switch expression does
PHP begin to execute the statements."



The context of those statements appears to be referring to the code
within the switch, as is inherent in the use of a switch: If you don't
hit a case that is true, then you don't execute the code in that case
block. It says nothing about the contents of the switch() call itself.



If you insist that this is desired behavior (a claim which I disagree
with), I'd at least recommend that the documentation be updated to make
this clear.


Previous Comments:
------------------------------------------------------------------------
[2010-09-20 14:37:33] [email protected]

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

Unless you have "case:" statements inside the switch the condition of
the switch 

never actually gets used, because it does not get used it means no
notices are 

being raised.

------------------------------------------------------------------------
[2010-08-18 12:17:41] brendel at krumedia dot de

If you add some cases to the switch the notice it triggered.

------------------------------------------------------------------------
[2010-07-24 08:21:08] gphemsley at gmail dot com

Description:
------------
If the parameter passed to switch() is an uninitialized variable, a PHP
Notice documenting such is not issued.

Test script:
---------------
<?php



error_reporting( E_ALL );



var_dump( PHP_VERSION, $mode );



switch( $mode )

{

    default:

        print '<p>There should be 2 notices of "undefined variable:
mode".<br />' . "\n";

        print 'One for the var_dump() and one for the switch().</p>' .
"\n";

    break;

}



highlight_file( $_SERVER['SCRIPT_FILENAME'] );



?> 

Expected result:
----------------
In the above script, two notices of "Undefined variable: mode" should be
issued, one for the var_dump() and one for the switch().

Actual result:
--------------
In reality, only one notice is issued: the one for the var_dump().
(Taking out that call means that no notices are issued.)



I've gotten confirmation that this is present in 5.2.4, 5.2.5, and
5.3.2.


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52426&edit=1

Reply via email to