how to create a php class which can be casted to boolean (be truthy or falsy)

前端 未结 6 999
闹比i
闹比i 2021-01-17 16:11

I am creating a collection class and would like it to be drop-in-replacement for arrays, which I use currently.

How to create a class which could be casted

6条回答
  •  [愿得一人]
    2021-01-17 16:41

    You cannot.

    In PHP an object when cast to bool always produces true. There is no way of changing that.

提交回复
热议问题