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
 [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: Mon Dec 30 14:01:28 2024 UTC