tags:

views:

195

answers:

4

what are the diff ways where we can use object operatos -> in php

+4  A: 

When accessing a method or a property of an instantiated class

class SimpleClass
{
    // property declaration
    public $var = 'a default value';

    // method declaration
    public function displayVar() {
        echo $this->var;
    }
}

$a = new SimpleClass();
echo $a->var;
$a->displayVar();
Mark Baker
like object->method_name(); or object->prop_name; it means its more like dot(.) operator to access class methods and attributes.
amanda
Similar to the . class operator in java, yes... but see the PHP class documentation for details
Mark Baker
+2  A: 

Call a function:

$foo->bar();

Access a property:

$foo->bar = 'baz';

where $foo is an instantiated object.

mmattax
+1  A: 

It is used in areas where functions or attributes of an object is referred. For eg: for class A{

with variable b; and function c(){}

also if there is a function f(){ it can call $this->c(), to access c;

}

}

If you have a object objA; you can call b as objA->b, and function 'c' as objA->c();

Wind Chimez
+1  A: 

PHP has two object operators.

The first, ->, is used when you want to call a method on an instance or access an instance property.

The second, ::, is used when you want to call a static method, access a static variable, or call a parent class's version of a method within a child class.

R. Bemrose