About 9,220,000 results
Open links in new tab
  1. PHP Nullable types and function parameters - Stack Overflow

    Sep 23, 2020 · You should instead use explicitly nullable which can be written in two ways: public function testSomething(?int $id = null) {} // With the '?' marker or. public function …

  2. Nullable (Optional) Types in PHP: A practical guide (5 examples)

    Feb 20, 2024 · Here’s how to use nullable types in class properties: public ? string $name = null; $user = new User (); $user ->name = "Alice"; // Or set to null $user ->name = null; This …

  3. php - Can I declare a typed property so that it accepts a null

    Mar 30, 2020 · PHP has support for nullable types since PHP 7.1. If you want to declare a property to be able to hold both a specific type or null, you prepend ? to the type declaration. …

  4. php - Nullable return types in PHP7 - Stack Overflow

    Nullable Types are available in PHP 7.1. This is a syntax example: public function getName(): ?string { return $this->name; // name can be null } PHP 7.1 is now GA and you can upgrade …

  5. PHP: Type declarations - Manual

    A single base type declaration can be marked nullable by prefixing the type with a question mark (?). Thus ?T and T|null are identical. Note: This syntax is supported as of PHP 7.1.0, and …

  6. Using Nullable Return Types in PHP - Tom McFarlin

    Jun 26, 2018 · Type declarations for parameters and return values can now be marked as nullable by prefixing the type name with a question mark. This signifies that as well as the specified …

  7. Typed properties in PHP 7.4 - stitcher.io

    Jun 30, 2019 · Using unset on a typed property will make it uninitialized, while unsetting an untyped property will make it null. Especially note that the following code, where an …

  8. Type Hinting with Nullable Types in PHP

    Type Hinting with Nullable Types in PHP. As of PHP 7.1, you can now set your type declarations as nullable by simply prefixing them with a question mark ?. In doing so a null value can be …

  9. How Do Nullable Types Work in PHP, and What Are the Syntax …

    Dec 9, 2024 · Nullable types provide a convenient way to handle nullable values in PHP. They allow you to declare that a variable, parameter, or return value can be either a specific type or …

  10. Nullable Types > PHP 7: The Important Stuff | SymfonyCasts

    This method returns null... which apparently is not a string. This actually made return types a pain in PHP 7... so in PHP 7.1, they fixed it! With "nullable" types. It works like this: if a return type …