php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64406 Protected method is called when i try to access to publicproperty with samename
Submitted: 2013-03-11 14:17 UTC Modified: 2013-03-11 14:45 UTC
From: me at felixcarmona dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.4Git-2013-03-11 (snap) OS: Linux
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: me at felixcarmona dot com
New email:
PHP Version: OS:

 

 [2013-03-11 14:17 UTC] me at felixcarmona dot com
Description:
------------
When i have a public property and private/protected method with the same name, i can't access to the property, because the method is called.
I'm using ->name; and NOT ->name();

Test script:
---------------
<?php
class Test
{
        public $test = 5;
        protected function test() { return 6; }
}

$test = new Test();
echo $test->test;

Expected result:
----------------
5

Actual result:
--------------
Fatal error: Call to protected Test::test() from invalid context



Patches

none (last revision 2013-03-11 14:19 UTC by me at felixcarmona dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-11 14:45 UTC] nikic@php.net
-Status: Open +Status: Not a bug
 [2013-03-11 14:45 UTC] nikic@php.net
test() is the constructor in your case (as the class is called "Test"). You get the error when the object is constructed, not when accessing the property ;)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 26 14:00:03 2025 UTC