Phonexay Singharatsavong

Phonexay Singharatsavong

Who am I?

I have been programming for over 20 years and wanted to start a blog about things I have learned over the years, am still learning, and will be learning, feel free to contact me.


What I write about


Recent Posts

PHP 7.2 Object Type Hinting

In PHP 7.2 we now have the ability to type hint an object. In previous versions of PHP we can type hint such things as a boolean, array, etc.... Having the ability to type hint is pretty useful if you are working on big teams this can be helpful with readability.

Not everyone is a fan of type hinting in PHP, but type hinting becomes very usesful in my opinion on teams that are more then 5 developers and even then it is a good practice I do now. If you are using PHP Storm it makes it very easy to see what you can pass to a function, instead of trying to figure out what the parameters should be to a function.

Here is an example of object type hinting:

class User {
    ...
}
$myclass = new User;

function test(User $arg) : Object {
    return $arg;
}

As a developer, I rather pass objects around then primitive types. This was a practice I like in Java and miss, hopefully with new feature, object type hinting will be used more.