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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
32 - 11 = ?
Subscribe to this entry?

 
 [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: Thu Apr 18 23:01:27 2024 UTC