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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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 05:00:02 2025 UTC