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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 14:01:30 2024 UTC