How to check if a variable is primitive in PHP

What would be the best (most efficient, easiest to understand in code, etc.) way to check if a variable has a primitive type in PHP?

Should I go "positive" (for example, is_string() || is_int()...) , or vice versa !is_array() && __is_object().. or maybe some even more convenient way?

+7
source share
3 answers

You are looking for is_scalar () .

+17
source

I would use is_type () positive, because it is more logical, and in tired times you will be confused with all the negatives.

0
source

Well, the easiest way to read the code is probably to define is_primitive_type() . I doubt that efficiency is the real concern for such a simple operation.

0
source

All Articles