Cannot access public properties?

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
MeroD
New php-forum User
New php-forum User
Posts: 53
Joined: Wed Oct 10, 2012 12:14 am

Mon Oct 29, 2012 11:03 pm

Code: Select all

class MyClass
{
    public $public = 'Public';
    protected $protected = 'Protected';
    private $private = 'Private';

    function printHello()
    {
        echo $this->public;
        echo $this->protected;
        echo $this->private;
    }
}

$obj = new MyClass();
echo $obj->public; // Works
echo $obj->protected; // Fatal Error
echo $obj->private; // Fatal Error
$obj->printHello(); // Shows Public, Protected and Private
http://www.php.net/manual/en/language.o ... bility.php

MeroD
New php-forum User
New php-forum User
Posts: 53
Joined: Wed Oct 10, 2012 12:14 am

Wed Oct 31, 2012 10:50 pm

Nope, sorry...

Maybe one of the other OO experts on here can help. Maybe try asking this question on Stackoverflow?

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 2 guests