0

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

3
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Shanti C
0

:: 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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.