#38824 [NEW]: settype() should throw a Notice on uninitialized variables

Ask a Question related to PHP Bugs, Design and Development.

  1. #1

    Default #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

  2. Similar Questions and Discussions

    1. 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...
    2. #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...
    3. #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...
    4. #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,...
    5. 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 ...
  3. #2

    Default #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

  4. #3

    Default #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

  5. #4

    Default #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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139