Bug #66577 [NEW]: Variable assignment in Constructor call.
From: pete at petermcdonald dot co dot uk
Operating system: linux
PHP version: Irrelevant
Package: Class/Object related
Bug Type: Bug
Bug description:Variable assignment in Constructor call.
Description:
------------
In all honesty this is not my discovery however located at
https://www.facebook.com/permalink.php?story_fbid=215062192030452&id=147594855443853
however I have been unable to locate a bug report for this.
It appears that the scripts that do contain a constructor
(both old style php 4 and new style php 5) over ride the value of a
variable in the main scope of the script. This appears to be caused by
the user specifying a default value when calling the constructor instead
of specifying in the constructor itself.
Would it not be beneficial to report an error rather than cause the
value being assigned to the variable in the main scope of the script.
Test script:
---------------
<?php
class Foo {}
$a = null;
$f = new Foo($a = 123);
var_dump($a);
// NULL as expected
class Foo { function __construct(){} }
$a = null;
$f = new Foo($a = 123);
var_dump($a);
// int(123) what????
class Foo2 { function Foo2(){} }
$a = null;
$f = new Foo($a = 123);
var_dump($a);
// int(123) what????
Expected result:
----------------
NULL
NULL
NULL
Actual result:
--------------
NULL
int(123)
int(123)
--
Edit bug report at https://bugs.php.net/bug.php?id=66577&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66577&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66577&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66577&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66577&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66577&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66577&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66577&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66577&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66577&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66577&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66577&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66577&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66577&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66577&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66577&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66577&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66577&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66577&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66577&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66577&r=mysqlcfg
Thread (6 messages)
- pete at petermcdonald dot co dot uk