php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76246 cannot access private variable in file included in method
Submitted: 2018-04-21 03:50 UTC Modified: 2018-04-21 04:14 UTC
From: miklcct at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.2.4 OS: Debian
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: miklcct at gmail dot com
New email:
PHP Version: OS:

 

 [2018-04-21 03:50 UTC] miklcct at gmail dot com
Description:
------------
An included file inside a class method cannot access class private member, but can access protected member

Test script:
---------------
// View.php
class View {
    private $data = 'test';
    public function render() {
        require 'view.phtml'
    }
}
(new View)->render();

// view.phtml
<html><head><title>$this->data</title></head><body></body></html>

Expected result:
----------------
An HTML with title test is returned

Actual result:
--------------
A fatal error saying cannot access private property

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-04-21 04:06 UTC] requinix@php.net
-Status: Open +Status: Feedback -Package: PHP Language Specification +Package: Scripting Engine problem
 [2018-04-21 04:06 UTC] requinix@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

Works for me. Hacked out a single-file version too: https://3v4l.org/Qv730
 [2018-04-21 04:13 UTC] miklcct at gmail dot com
-Status: Feedback +Status: Closed
 [2018-04-21 04:13 UTC] miklcct at gmail dot com
Sorry, my mistake
 [2018-04-21 04:13 UTC] miklcct at gmail dot com
Sorry, my mistake
 [2018-04-21 04:14 UTC] requinix@php.net
-Status: Closed +Status: Not a bug
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 09 09:01:35 2025 UTC