php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71461 Able to access private property outside class
Submitted: 2016-01-27 09:51 UTC Modified: 2016-01-27 09:56 UTC
From: vikashchaudhary10 at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.0.2 OS: Linux Ubuntu 15.10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
17 - 2 = ?
Subscribe to this entry?

 
 [2016-01-27 09:51 UTC] vikashchaudhary10 at gmail dot com
Description:
------------
I have a class having two private property named name and age. I have created object outside of class and able to access those private property outside class.
Please look into this issue also let us know why is it working properly?

Test script:
---------------
<?php
class Person
{
    private $name;

    private $age;
}

class Student extends Person
{
    public $rollNo;

    public $marks;
}

$object = new Student();
$object->name = 'Vikash';
$object->age = 30;
echo $object->name;

Expected result:
----------------
Must through fatal error

Actual result:
--------------
Vikash

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-01-27 09:56 UTC] chx@php.net
-Status: Open +Status: Not a bug -Package: PHP Language Specification +Package: Scripting Engine problem
 [2016-01-27 09:56 UTC] chx@php.net
You are adding new properties to the class not accessing the parent properties.
 [2023-11-10 15:25 UTC] ragafa5955 at glalen dot com
<
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 04:01:31 2024 UTC