Ask a Question related to PHP Bugs, Design and Development.
-
tklingenberg at lastflood dot com #1
#38824 [NEW]: settype() should throw a Notice on uninitialized variables
From: tklingenberg at lastflood dot com
Operating system: win32
PHP version: 5.1.6
PHP Bug Type: Feature/Change Request
Bug description: settype() should throw a Notice on uninitialized variables
Description:
------------
In case a program uses an uninitialized variable passed to settype(), it
should throw a Notice, compareable to echo; intval() and other variable
related functions.
Even if PHP does everything right ($var is a variable you can change the
type of), for the PHP User, it's highly possible she/he made an error and
typed in the wrong variable name. Afterwards the type of the variable is
unchecked, which can lead to even more critical errors.
All this is unnoticed because PHP does not throw a NOTICE.
Reproduce code:
---------------
<?php
$r = settype($var, "float");
?>
Expected result:
----------------
It should throw a Notice
Actual result:
--------------
No Notice is giving that $var is not initialized.
--
Edit bug report at [url]http://bugs.php.net/?id=38824&edit=1[/url]
--
Try a CVS snapshot (PHP 4.4): [url]http://bugs.php.net/fix.php?id=38824&r=trysnapshot44[/url]
Try a CVS snapshot (PHP 5.2): [url]http://bugs.php.net/fix.php?id=38824&r=trysnapshot52[/url]
Try a CVS snapshot (PHP 6.0): [url]http://bugs.php.net/fix.php?id=38824&r=trysnapshot60[/url]
Fixed in CVS: [url]http://bugs.php.net/fix.php?id=38824&r=fixedcvs[/url]
Fixed in release: [url]http://bugs.php.net/fix.php?id=38824&r=alreadyfixed[/url]
Need backtrace: [url]http://bugs.php.net/fix.php?id=38824&r=needtrace[/url]
Need Reproduce Script: [url]http://bugs.php.net/fix.php?id=38824&r=needscript[/url]
Try newer version: [url]http://bugs.php.net/fix.php?id=38824&r=oldversion[/url]
Not developer issue: [url]http://bugs.php.net/fix.php?id=38824&r=support[/url]
Expected behavior: [url]http://bugs.php.net/fix.php?id=38824&r=notwrong[/url]
Not enough info: [url]http://bugs.php.net/fix.php?id=38824&r=notenoughinfo[/url]
Submitted twice: [url]http://bugs.php.net/fix.php?id=38824&r=submittedtwice[/url]
register_globals: [url]http://bugs.php.net/fix.php?id=38824&r=globals[/url]
PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=38824&r=php3[/url]
Daylight Savings: [url]http://bugs.php.net/fix.php?id=38824&r=dst[/url]
IIS Stability: [url]http://bugs.php.net/fix.php?id=38824&r=isapi[/url]
Install GNU Sed: [url]http://bugs.php.net/fix.php?id=38824&r=gnused[/url]
Floating point limitations: [url]http://bugs.php.net/fix.php?id=38824&r=float[/url]
No Zend Extensions: [url]http://bugs.php.net/fix.php?id=38824&r=nozend[/url]
MySQL Configuration Error: [url]http://bugs.php.net/fix.php?id=38824&r=mysqlcfg[/url]
tklingenberg at lastflood dot com Guest
-
Please help b4 I throw my computer
Hi, I'm trying to create a form that will be then emailed. I have text input boxes for name address etc and some check boxes so the user can... -
#26027 [Bgs]: settype($array, 'string') always raises a notice
ID: 26027 User updated by: mike@php.net Reported By: mike@php.net Status: Bogus Bug Type: Arrays related PHP... -
#26027 [Opn->Bgs]: settype($array, 'string') always raises a notice
ID: 26027 Updated by: sniper@php.net Reported By: mike@php.net -Status: Open +Status: Bogus Bug Type: Arrays related PHP... -
#26027 [NEW]: settype($array, 'string') always raises a notice
From: mike@php.net Operating system: PHP version: 4.3.3 PHP Bug Type: Arrays related Bug description: settype($array,... -
Use of uninitialized value
What may be wrong with my codes? Perl complains of use of uninitialized value at addition and in range (or flop). Thanks ... -
tony2001@php.net #2
#38824 [Opn->WFx]: settype() should throw a Notice on uninitialized variables
ID: 38824
Updated by: [email]tony2001@php.net[/email]
Reported By: tklingenberg at lastflood dot com
-Status: Open
+Status: Wont fix
Bug Type: Feature/Change Request
Operating System: win32
PHP Version: 5.1.6
New Comment:
It's just impossible.
settype() function accepts the first parameter by reference.
See fo example:
<?php
function create_a_var(&$var) {
$var = 'created';
}
create_a_var($doesnt_exist); // you would not expect a NOTICE here,
right?
?>
settype() does the same.
Previous Comments:
------------------------------------------------------------------------
[2006-09-14 11:07:13] tklingenberg at lastflood dot com
Description:
------------
In case a program uses an uninitialized variable passed to settype(),
it should throw a Notice, compareable to echo; intval() and other
variable related functions.
Even if PHP does everything right ($var is a variable you can change
the type of), for the PHP User, it's highly possible she/he made an
error and typed in the wrong variable name. Afterwards the type of the
variable is unchecked, which can lead to even more critical errors.
All this is unnoticed because PHP does not throw a NOTICE.
Reproduce code:
---------------
<?php
$r = settype($var, "float");
?>
Expected result:
----------------
It should throw a Notice
Actual result:
--------------
No Notice is giving that $var is not initialized.
------------------------------------------------------------------------
--
Edit this bug report at [url]http://bugs.php.net/?id=38824&edit=1[/url]
tony2001@php.net Guest
-
tklingenberg at lastflood dot com #3
#38824 [WFx]: settype() should throw a Notice on uninitialized variables
ID: 38824
User updated by: tklingenberg at lastflood dot com
Reported By: tklingenberg at lastflood dot com
Status: Wont fix
Bug Type: Feature/Change Request
Operating System: win32
PHP Version: 5.1.6
New Comment:
Accepting a parameter by reference does not mean it's impossible to
check for an uninitalized variable:
<?php
function unintialize_a_var(&$var) {
if (!isset($var)) {
// Why should I uninitalize something uninitialized?
} else {
$var = NULL;
}
}
uninitialize_a_var($uninitialized); // you would expect a NOTICE here,
right?
?>
Anyway your (and mine) example function is useless, and it does not
point to the problem itself afterall.
But if the function is about setting the type of a variable and the
variable is not initialized I would strongly assume to get a NOTICE
about this. Especially in PHP where a variable is created by using the
dollarsign followed by the variabelename.
Would you expect to get a NOTICE here?:
echo $var;
var_dump($var);
intval($var);
I get a notice there. With your arguments you would not expect it here,
right?
Previous Comments:
------------------------------------------------------------------------
[2006-09-14 11:16:54] [email]tony2001@php.net[/email]
It's just impossible.
settype() function accepts the first parameter by reference.
See fo example:
<?php
function create_a_var(&$var) {
$var = 'created';
}
create_a_var($doesnt_exist); // you would not expect a NOTICE here,
right?
?>
settype() does the same.
------------------------------------------------------------------------
[2006-09-14 11:07:13] tklingenberg at lastflood dot com
Description:
------------
In case a program uses an uninitialized variable passed to settype(),
it should throw a Notice, compareable to echo; intval() and other
variable related functions.
Even if PHP does everything right ($var is a variable you can change
the type of), for the PHP User, it's highly possible she/he made an
error and typed in the wrong variable name. Afterwards the type of the
variable is unchecked, which can lead to even more critical errors.
All this is unnoticed because PHP does not throw a NOTICE.
Reproduce code:
---------------
<?php
$r = settype($var, "float");
?>
Expected result:
----------------
It should throw a Notice
Actual result:
--------------
No Notice is giving that $var is not initialized.
------------------------------------------------------------------------
--
Edit this bug report at [url]http://bugs.php.net/?id=38824&edit=1[/url]
tklingenberg at lastflood dot com Guest
-
tony2001@php.net #4
#38824 [WFx]: settype() should throw a Notice on uninitialized variables
ID: 38824
Updated by: [email]tony2001@php.net[/email]
Reported By: tklingenberg at lastflood dot com
Status: Wont fix
Bug Type: Feature/Change Request
Operating System: win32
PHP Version: 5.1.6
New Comment:
It's impossible to detect what you really want to get - either create a
variable or get a notice.
PHP cannot get into your head and read it.
Previous Comments:
------------------------------------------------------------------------
[2006-09-14 11:36:29] tklingenberg at lastflood dot com
Accepting a parameter by reference does not mean it's impossible to
check for an uninitalized variable:
<?php
function unintialize_a_var(&$var) {
if (!isset($var)) {
// Why should I uninitalize something uninitialized?
} else {
$var = NULL;
}
}
uninitialize_a_var($uninitialized); // you would expect a NOTICE here,
right?
?>
Anyway your (and mine) example function is useless, and it does not
point to the problem itself afterall.
But if the function is about setting the type of a variable and the
variable is not initialized I would strongly assume to get a NOTICE
about this. Especially in PHP where a variable is created by using the
dollarsign followed by the variabelename.
Would you expect to get a NOTICE here?:
echo $var;
var_dump($var);
intval($var);
I get a notice there. With your arguments you would not expect it here,
right?
------------------------------------------------------------------------
[2006-09-14 11:16:54] [email]tony2001@php.net[/email]
It's just impossible.
settype() function accepts the first parameter by reference.
See fo example:
<?php
function create_a_var(&$var) {
$var = 'created';
}
create_a_var($doesnt_exist); // you would not expect a NOTICE here,
right?
?>
settype() does the same.
------------------------------------------------------------------------
[2006-09-14 11:07:13] tklingenberg at lastflood dot com
Description:
------------
In case a program uses an uninitialized variable passed to settype(),
it should throw a Notice, compareable to echo; intval() and other
variable related functions.
Even if PHP does everything right ($var is a variable you can change
the type of), for the PHP User, it's highly possible she/he made an
error and typed in the wrong variable name. Afterwards the type of the
variable is unchecked, which can lead to even more critical errors.
All this is unnoticed because PHP does not throw a NOTICE.
Reproduce code:
---------------
<?php
$r = settype($var, "float");
?>
Expected result:
----------------
It should throw a Notice
Actual result:
--------------
No Notice is giving that $var is not initialized.
------------------------------------------------------------------------
--
Edit this bug report at [url]http://bugs.php.net/?id=38824&edit=1[/url]
tony2001@php.net Guest



Reply With Quote

