What's the best way of checking if an object property in php is undefined?
Asked
Active
Viewed 170 times
2
-
3`is_null()` or `=== null`. – u_mulder Feb 07 '19 at 11:22
-
1Best way is opinion based – Andreas Feb 07 '19 at 11:26
-
2No @Andreas its code for "dont have a clue" – RiggsFolly Feb 07 '19 at 11:27
-
2@RiggsFolly I know. But that "code" means there is a close reason. Asking the same question correct is better. Although in this case it didn't make any difference. – Andreas Feb 07 '19 at 11:29
1 Answers
1
You can use is_null
Or
!isset($object)
Example :
I want to check if the input is undefined. So, I can show errors.
if (!isset($_POST['myInput'])) { echo "error"; } else { // do the code }

Hema D.
- 140
- 2
- 5
- 17