php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52386 ReflectionClass scope problem
Submitted: 2010-07-21 13:16 UTC Modified: 2010-07-22 07:00 UTC
From: laszlo dot janszky at gmail dot com Assigned:
Status: Not a bug Package: Reflection related
PHP Version: 5.3.2 OS: xp
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: laszlo dot janszky at gmail dot com
New email:
PHP Version: OS:

 

 [2010-07-21 13:16 UTC] laszlo dot janszky at gmail dot com
Description:
------------
Maybe it's not a bug, but I cannot call private or protected methods from within a class by ReflectionClass.

Test script:
---------------
<?php

class Test
{
	static public function instance()
	{
		$class=new ReflectionClass(get_called_class());
		return $class->newInstanceArgs(func_get_args());
	}
	
	private function __construct()
	{}
}

Test::instance();

Expected result:
----------------
Create a new instance.

Actual result:
--------------
Fatal error: Uncaught exception 'ReflectionException' with message 'Access to non-public constructor of class Test'

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-22 05:01 UTC] aharvey@php.net
-Status: Open +Status: Bogus
 [2010-07-22 05:01 UTC] aharvey@php.net
That's by design -- reflection's not intended to provide a backdoor
around the usual access specification mechanism.
 [2010-07-22 07:00 UTC] laszlo dot janszky at gmail dot com
Ok.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Oct 08 21:01:27 2024 UTC