Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / PHP

Object member access (->)

Select an instance property or call an instance method of the object on the left.

Version: PHP 8.4; repository runtime, production runtime not attested

Syntax

$object->property
$object->method()

Select an instance property or call an instance method of the object on the left. Access is subject to visibility, and a method uses that particular object as its receiver. Two instances of the same class can hold different property values. A null receiver needs an explicit check or null-safe access.

$object->property
$object->method()
[1,0]

Examples

<?php
class Counter { public int $value = 0; public function tick(): void { ++$this->value; } }
$a = new Counter();
$b = new Counter();
$a->tick();
echo json_encode([$a->value, $b->value]);

Result

[1,0]

Sources