php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #48355 Direct access to protected properties and methods
Submitted: 2009-05-21 12:58 UTC Modified: 2009-05-24 18:10 UTC
From: gaj dot capuder at spletna-postaja dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.3.0RC2 OS: Vista
Private report: No CVE-ID: None
 [2009-05-21 12:58 UTC] gaj dot capuder at spletna-postaja dot com
Description:
------------
When accessing object properties directly witin object's parent (the one which object extends) the property acts as if it was public (no error).

Similar thing happens with protected constructors where new instance of a certain class can be created using "new" when the call is made inside of an object which is the parent or which extends the same parent.

Reproduce code:
---------------
class A {

	public function access()
	{
		$b = new B;	
		echo $b->property;
	}
	
}


class B extends A {

	protected $property = 'Should be protected';
	
}

class C extends A {
		
}

$c = new C;
$c->access();

$b = new B;
echo $b->property;

Expected result:
----------------
Fatal error: Cannot access protected property B::$property

Actual result:
--------------
Protection is broken 
Fatal error: Cannot access protected property B::$property

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-24 18:10 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

.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 04 16:01:31 2024 UTC