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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: vikashchaudhary10 at gmail dot com
New email:
PHP Version: OS:

 

 [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 05:01:30 2024 UTC