Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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 $property;
}

?>

Alternatives

  • Use another type for the property.
  • Remove the property.
  • Use the null type.