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 Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or 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)

Add a Patch

Pull Requests

Add a Pull Request

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: Fri Mar 29 11:01:29 2024 UTC