CKTIS / PHP
PHP type object
The object declaration accepts any object, without guaranteeing that a particular method or property exists.
Version: PHP 8.4; repository runtime, production runtime not attested
Syntax
function renameLabel(object $record): voidThe object declaration accepts any object, without guaranteeing that a particular method or property exists. Specify an interface when an operation requires a particular method. Passing an object copies its handle, so a change to a declared property is visible to the caller even without a reference parameter.
class Label { public string $name = 'old'; }
function renameLabel(object $record): void { if ($record instanceof Label) { $record->name = 'new'; } }
$tag = new Label();
renameLabel($tag);
echo json_encode([$tag->name, is_object([])]);
["new",false]
Examples
<?php
class Label { public string $name = 'old'; }
function renameLabel(object $record): void { if ($record instanceof Label) { $record->name = 'new'; } }
$tag = new Label();
renameLabel($tag);
echo json_encode([$tag->name, is_object([])]);
Result
["new",false]