---
title: "Discussion on \"Doing stricter checks in PHP\" | Hashnode"
description: "Discussion on \"Doing stricter checks in PHP\". A nice refactoring I've learned recently is to utilize types in conditionals.\nFor years I’ve been doing if (!empty($posts)), but Rector, a tool to automatically refactor code, changed that to if ($posts === []). The main advantage of using $posts ===..."
url: "https://hashnode.com/posts/doing-stricter-checks-in-php/6431e0e593ca2d4575fcf3aa"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Doing stricter checks in PHP](https://blog.genijaho.dev/doing-stricter-checks-in-php?utm_source=hashnode&utm_medium=feed)

A nice refactoring I've learned recently is to utilize types in conditionals. For years I’ve been doing if (!empty($posts)), but Rector, a tool to automatically refactor code, changed that to if ($posts === \[\]). The main advantage of using $posts ===...

Apr 8, 2023 · 3 min read · blog.genijaho.dev  
Read the article

-   [#php](https://hashnode.com/tag/php)
-   [#laravel](https://hashnode.com/tag/laravel)
-   [#refactoring](https://hashnode.com/tag/refactoring)
-   [#webdev](https://hashnode.com/tag/webdev)
-   [#rector](https://hashnode.com/tag/rector)

## Written by

[Geni Jaho](https://hashnode.com/@genijaho)

@genijaho

  
[View profile](https://hashnode.com/@genijaho)

It's not a bug, it's a lifestyle!

Full-stack web dev with a passion for software architecture and programming best coffees.

## Responses 3

Markdown supported · ⌘↵ to post

[Lasse Larsen](https://hashnode.com/@Iamlasse)

[May 23, 2025](https://hashnode.com/posts/doing-stricter-checks-in-php/6431e0e593ca2d4575fcf3aa/comment/68308ef0ccde6bc325c82395)

I do prefer data\_get over the array key approach. Mainly because it simplifies the getting, as well as having a default null or value.

[Erland Muchasaj](https://hashnode.com/@erlandmuchasaj)

[Apr 11, 2023](https://hashnode.com/posts/doing-stricter-checks-in-php/6431e0e593ca2d4575fcf3aa/comment/643525816699be6a40d4bbd9)

[Geni Jaho](https://hashnode.com/@genijaho) array\_key\_exists() and isset() are not interchangeable, because they have different use cases.

Of course most of the time you can use array\_key\_exists instead of isset but in some cases, you can not.

See [here](https://medium.com/@erlandmuchasaj/isset-vs-array-key-exists-b5b054f63eea) for more details

[Lars Moelleken](https://hashnode.com/@voku)

[Apr 9, 2023](https://hashnode.com/posts/doing-stricter-checks-in-php/6431e0e593ca2d4575fcf3aa/comment/643303a394d1164842d9c6fe)

`count($a) === 0` is even more readable, or? 🤔

[Geni Jaho](https://hashnode.com/@genijaho)

[Apr 9, 2023](https://hashnode.com/posts/doing-stricter-checks-in-php/6431e0e593ca2d4575fcf3aa/comment/643303a394d1164842d9c6fe#reply-643309d794d1164842d9c7f3)

I think yes, it's at the same level as **empty($a)**, but the point is we're letting go of a tiny bit of readability in exchange for a more trusted/clear code. When we do **$a === \[\]** we know for sure that it's a plain array and not an Arrayable object or similar. It's down to personal preference anyway.
