Falsifiable objects

I submitted an RFC to the PHP internals community on allowing objects to be declared false. Before the RFC submission, I sent an email out to try and judge community desire and positions. No one seemed violently opposed to the idea, which is described in the RFC, and I’ve decided to go ahead and start trying to implement it myself.

In the beginning I wasn’t really sure what I was trying to accomplish for the PHP community at large; only what I wanted for myself.

My initial commit for 8fold Shoop was May 9th, 2019. That’s not when I first started working on the precursor for it though. I mean it’s close enough. I posted a video on a String class to the YouTube channel in April of that same year. What started as an exercise in objectification of a PHP base type turned into a library that I quite enjoy using.

Shoop has a fair amount of methods that return booleans or, in the case of Shoop, ESBool:

$bool = Shoop::string("Hello")->isEmpty;
// output: false

$bool = Shoop::string("")->isEmpty;
// output: true

I know that’s not a method call but it’s basically the shortest way to unwrap thre result of a method in Shoop. It’s equivalent to either of the following:

$bool = Shoop::string("Hello")->isEmptyUnfolded();
// output: false

$bool = Shoop::string("")->isEmpty()->unfold();
// output: true

To introduce a conditional-like construct to Shoop I made it so these types of methods could take a Closure. The result of the bool check would be passed as the first argument as an ESBool. The second argument would be the original Shoop instance. Something like this:

Shoop::string("Hello")->isEmpty(function($result, $string) {
  if ($result->unfold()) {
    // respond to empty string
  // respond to non-empty stsring

I want the power and flexibility of Shoop with the result, but I don’t like having to call unfold() every time. Further, any valid instance of an object in PHP is always true.

This is not good enough reason to add a feature to a programming language.

That’s why I initially just submitted the idea as a concept and tried to keep it personally ambiguous.

It started as casting to bool - quickly turned into declaring emptiness - and is now about being able to declare an object as false, which just so happens to declare its emptiness and response to bool casting. However, the implementation should leave the door open to things like being able to declare the emptiness of an object later.

I’m not a metal-to-user developer. I don’t use terminal as much as my peers. I’m self-taught. Never done anything in straight C. Basically, I’m probably the last person who should be trying to implement this thing. But here we are.

This is that journey. Let’s see where it takes us.

Falsifiable objects essays