|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-01-31 12:13 UTC] johannes@php.net
-Status: Open
+Status: Not a bug
[2013-01-31 12:13 UTC] johannes@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Nov 18 17:00:01 2025 UTC |
Description: ------------ When calling non-static method from object method, that method has wrong $this, pointing to object from which call does (example one). Also it is security problem - attacker may "override" (not real overriding) private method (example two). Test script: --------------- Example one: class A { function aaa() { echo get_class($this); } } class B { function bbb() { A::aaa(); } } (new B())->bbb(); Example two: class PasswordManager { private function getPasswordHash($rawPassword) { return md5($rawPassword); } private function isPasswordValid($rawPassword, $hashPassword) { return $hashPassword === $this->getPasswordHash($rawPassword); } public function authorize($rawPassword, $hashPassword) { if ($this->isPasswordValid($rawPassword, $hashPassword)) { echo "Congratulations! You are authorized!\n"; return true; } echo "Sorry! Authorization failed!\n"; return false; } } class Attacker { public function isPasswordValid($a, $b) { return true; } public function doAttack() { PasswordManager::authorize(null, null); } } (new Attacker())->doAttack(); Expected result: ---------------- Example 1: NULL Actual result: -------------- Example 1: B