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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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 12:01:31 2024 UTC