Property x::$p cannot have type void

Description

Void is a type, that can only be used with return type, on methods or functions. Here, void represents the absence of value: this is not possible for a property or an argument. The null value is then the closest possible type that can be assigned to a property, yet representing no value.

Example

<?php

class x {
    private void $p;
}

?>

Solutions

  • Use another type for the property.

  • Remove the property.

  • Use the null type.

See Also