php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38821 settype() creates variable "by reference"
Submitted: 2006-09-14 09:51 UTC Modified: 2006-09-14 10:53 UTC
From: tklingenberg at lastflood dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.1.6 OS: win32
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: tklingenberg at lastflood dot com
New email:
PHP Version: OS:

 

 [2006-09-14 09:51 UTC] tklingenberg at lastflood dot com
Description:
------------
settype() needs a variable passed by reference.

if this variable is not defined/set, it does not throw an error. instead, and that is the bug per se, settype creates the variable passed "by reference".


Reproduce code:
---------------
<?
/* $var does not exsits, this throws an error */
var_dump($var);

/* settype should work on existing vars only (by &reference) */
$r = settype($var, "string");

/* $var does exist now */
var_dump($var);
?>


Expected result:
----------------
<br />
<b>Notice</b>:  Undefined variable: var in <b>test.php</b> on line <b>3</b><br />
NULL
<br />
<b>Notice</b>:  Undefined variable: var in <b>test.php</b> on line <b>6</b><br />
NULL


Actual result:
--------------
<br />
<b>Notice</b>:  Undefined variable: var in <b>test.php</b> on line <b>3</b><br />
NULL
string(0) ""

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-14 09:54 UTC] tony2001@php.net
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

bool settype ( mixed &var, string type )
 [2006-09-14 10:49 UTC] tklingenberg at lastflood dot com
I close this on behalf my own, because this really is BOGUS: In PHP there is no such thing like a nonexisting variable.

So infact, it's not settype() that creates the variable, it's PHP.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Dec 08 16:00:01 2025 UTC