what are the diff ways where we can use object operatos -> in php
views:
195answers:
4
+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
2010-06-14 13:24:21
like object->method_name(); or object->prop_name; it means its more like dot(.) operator to access class methods and attributes.
amanda
2010-06-14 13:26:32
Similar to the . class operator in java, yes... but see the PHP class documentation for details
Mark Baker
2010-06-14 13:29:25
+2
A:
Call a function:
$foo->bar();
Access a property:
$foo->bar = 'baz';
where $foo is an instantiated object.
mmattax
2010-06-14 13:25:06
+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
2010-06-14 13:48:11
+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
2010-06-14 13:50:39