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

 ID:                 64454
 Updated by:         larue...@php.net
 Reported by:        wolters dot fl at gmail dot com
 Summary:            It is possible to directly call the magic method
                     "__construct".
-Status:             Open
+Status:             Wont fix
 Type:               Feature/Change Request
 Package:            Class/Object related
 Operating System:   Microsoft Windows Version 6.2.9
 PHP Version:        5.4.13
 Block user comment: N
 Private report:     N

 New Comment:

PHP's __construct, actually, is not creating object, it decorate the object 
after 
it was created.

so,  even you directly call to $obj->__construct, then no new instance was 
create.

so a workaround is you can exam some property you set to see whether that is a 
double constructing or not.


thanks


Previous Comments:
------------------------------------------------------------------------
[2013-03-19 12:45:54] wolters dot fl at gmail dot com

Description:
------------
It is possible to directly call the magic method "__construct". This should NOT 
be possible, since one cannot create immutable objects with the current 
behaviour.

In addition, a direct call to the magic method "__clone" is not possible and 
raises an "\E_FATAL". Both magic methods deal with object creation, so the 
behaviour is inconsistent between them.

I am using "php-5.4.13-nts-Win32-VC9-x86" on Microsoft Windows Version 6.2.9 
x64(Windows 8 64 bit).

Test script:
---------------
https://gist.github.com/FlorianWolters/5195734

Expected result:
----------------
The method call:

$example->__construct();

should raise an "\E_FATAL" with the following message:

"Cannot call __construct() method on objects - use 'new <Class>' instead in 
[...] on line 21"



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



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

Reply via email to