I Want Scalar Objects in PHP

Recently, I read an interesting article from Andrew Carter entitled Make PHP Great Again [cheap plug: this link was included in my most recent Newsletter]. In it Andrew brought up the topic of scalar objects. If you’re not familiar with scalar objects, they represent a single value (integer, boolean, string, etc.) that you can perform operations on*. In PHP this could look something like:

* It’s important to note that, as far as I’ve been able to ascertain, the context in which you use the term “scalar” is important. Different languages implement and define scalar differently.

Soon after scalar objects were brought to the forefront of my mind, I came across the following tweet:

To which I replied:

The Case For Scalar Objects in PHP

If you read Andrew’s post he discusses how PHP’s core functions are inconsistent. This topic isn’t new:

PHP 8 is a great opportunity to cleanup these inconsistencies. Introducing scalar objects would provide a consistent API that would be more fluent and much more enjoyable to work with. Which of the following is more intuitive to you?

or

I know this is a silly example, but doesn’t the second bit of code just feel better?

Let’s get scalar objects in PHP 8! Who’s with me?!?

#ScalarIn8