I am passing $row
which has been assigned $statement->fetchAll();
to it I am passing it to another class and I want to check if it's an stdClass Object within the method, for example if I wanted to check if it was an array I would do
public function hello(array $row)
how would I do it to check if it was a stdClass Object ?
Finally is this called type hinting ?
Here is a little script that can help you to check if a variable is an object or if is a specific type of object, if not want to cast parameter function to desired type of object.
<?php
function text($a){
if(is_object($a)){
echo 'is object';
}else{
echo 'is not object';
}
//or if you want to be more accurate
if($a instanceof stdClass){
echo 'is object type stdClass';
}else{
echo 'is not object of type stdClass';
}
}
$b = new stdClass();
text($b);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With