php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52464 spl_autoload_register() can use protected/private methods if called from class
Submitted: 2010-07-28 01:08 UTC Modified: 2010-07-28 14:15 UTC
From: delphists at apollo dot lv Assigned:
Status: Not a bug Package: SPL related
PHP Version: 5.3.3 OS: Windows 7, Linux Slackware
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: delphists at apollo dot lv
New email:
PHP Version: OS:

 

 [2010-07-28 01:08 UTC] delphists at apollo dot lv
Description:
------------
If spl_autoload_register() is called from class method, SPL autoloader can use private and protected methods, although SPL is not a part of this class. It works well if spl_autoload_register() is called from somewhere else.

Test script:
---------------
<?php
	class CallbackTest {
		public function __construct() {
			spl_autoload_register(array($this, 'publicCallback'));
			spl_autoload_register(array($this, 'protectedCallback'));
			spl_autoload_register(array($this, 'privateCallback'));
		}
		public function publicCallback($className) {
			echo __METHOD__, "\n";
		}
		protected function protectedCallback($className) {
			echo __METHOD__, "\n";
		}
		private function privateCallback($className) {
			echo __METHOD__, "\n";
		}
	}
	new CallbackTest();
	new AutoloadTest();


Expected result:
----------------
PHP Fatal error:  Uncaught exception 'LogicException' with message 'Passed array does not specify a callable method (cannot access protected method CallbackTest::protectedCallback())' in /home/binary/test.php:5
Stack trace:
#0 test.php(5): spl_autoload_register(Array)
#1 test.php(18): CallbackTest->__construct()
#2 {main}
  thrown in test.php on line 5

Actual result:
--------------
CallbackTest::publicCallback
CallbackTest::protectedCallback
CallbackTest::privateCallback
PHP Fatal error:  Class 'AutoloadTest' not found in test.php on line 19


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-07-28 14:15 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2010-07-28 14:15 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is made on purpose.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 05:01:33 2025 UTC