Cannot access public properties?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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

Re: Cannot access public properties?

Post by MeroD » 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

Re: Cannot access public properties?

Post by MeroD » 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

Who is online

Users browsing this forum: Baidu [Spider], phpnoob and 1 guest