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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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: Sun Dec 22 06:01:30 2024 UTC