The undefined Keyword

By Hammed Oyedele

<?php

 declare(strict_types = 1);

if (! class_exists('undefined')) {
   class undefined {}
}

if (! defined('undefined')) {
   define('undefined',  new undefined());
}

class X {
  function foo(
      SomeType|undefined $object = undefined,
      bool|undefined $option = undefined,
  ) {
     return match($object) {
       undefined => new DefaultBehavior(),
       default => $object->someMethod()
     };
  }
}

This is valid PHP code.

Well, I just discovered you can use an object instance as a constant and also have a class with the same name in PHP.

Laravel have the same concept for missing values except they didn’t actually create a global constant for it.

This would upset some people for sure, but proof of concepts are not a crime!

See Also

PHP Features

Last updated: 14 July 2026