Type hinting generic objects

suggest change

PHP 7.2 added the built-in object type for a function that accepts an instance of any class. It does not accept scalar values, arrays, or resources.

<?php

function doSomething(object $object): object
{
    return $object;
}

class ClassOne {}
class ClassTwo {}

$classOne = new ClassOne();
$classTwo = new ClassTwo();

doSomething($classOne);
doSomething($classTwo);

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents