Dear all,

Why below program not working .It gives fatal error.

NOT WORKING

<?php
class Class_access{
        const a="50";
        public $bb="Class Variable \n";
        function display(){
                //$Function_Variable;
                echo "Function Display \n  ";
                //echo $this->bb;
        }

}
$obj=new Class_access();
$obj->display();
echo Class_access::a;
echo "\n";
echo Class_access::$bb;
?>

WOKING
======

<?php
class Class_access{
        const a="50";
        public static $bb="Class Variable \n";
        function display(){
                //$Function_Variable;
                echo "Function Display \n  ";
                //echo $this->bb;
        }

}
$obj=new Class_access();
$obj->display();
echo Class_access::a;
echo "\n";
echo Class_access::$bb;
?>

Can any one help me out .What is the difference among them.

Thank you,

With Regards,
Prem

Recommended Answers

The variable $bb is declared static in the latter example. But I suggest you'd better read this

Jump to Post

All 2 Replies

The variable $bb is declared static in the latter example. But I suggest you'd better read this manual to get a better understanding between classes and objects.

:: is for referencing static properties or methods of a class. -> is for referencing instance properties and methods.
check line 4 for static is missing in first example.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.