php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66944 can't instance protected construct
Submitted: 2014-03-23 12:48 UTC Modified: 2014-03-23 12:56 UTC
From: ian dot email at qq dot com Assigned:
Status: Not a bug Package: Reflection related
PHP Version: 5.4.26 OS: windows
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: ian dot email at qq dot com
New email:
PHP Version: OS:

 

 [2014-03-23 12:48 UTC] ian dot email at qq dot com
Description:
------------
class A{ protected function __construct(){} }
why can't set private/protected construct
$method=$class->getmethod('__construct');
$method->setAccessible(true);
$fuc=$class->newInstance(true);

Test script:
---------------
class A{ protected function __construct(){} }
why can't set private/protected construct
$method=$class->getmethod('__construct');
$method->setAccessible(true);
$fuc=$class->newInstance(true);

Expected result:
----------------
class A{ protected function __construct(){} }
why can't set private/protected construct
$method=$class->getmethod('__construct');
$method->setAccessible(true);
$fuc=$class->newInstance(true);

Actual result:
--------------
class A{ protected function __construct(){} }
why can't set private/protected construct
$method=$class->getmethod('__construct');
$method->setAccessible(true);
$fuc=$class->newInstance(true);

Patches

protectedConstruct (last revision 2014-03-23 12:50 UTC by ian dot email at qq dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-03-23 12:56 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-03-23 12:56 UTC] requinix@php.net
It doesn't matter what you do with $method - the class's constructor is protected you so can't instantiate it that way. However you can do a newInstanceWithoutConstructor() and then call $method on the instance it returns.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC