Accessing a custom object with instanceof - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Accessing a custom object with instanceof (/showthread.php?tid=78474) |
Accessing a custom object with instanceof - baxterheinen - 01-25-2021 I have instantiated a new object from a class in my app/libraries folder as such: PHP Code: // in controller PHP Code: // in controller method But when I pass $account to my model and check if it is an instance of LN_Account the conditional fails. PHP Code: // in controller method PHP Code: // in model How do I make LN_Account visible to my model? RE: Accessing a custom object with instanceof - craig - 01-26-2021 In model: Code: use App\Libraries\LN_Account; You can also do the following in getAuthenticationCredentials() to show details about the variable: Code: d($account); RE: Accessing a custom object with instanceof - baxterheinen - 01-26-2021 I tried adding that to the Model with no luck. Same error. I have been using CI3 for like 8 years so not a n00b here, and PHP for 15 years. This one has me stumped. RE: Accessing a custom object with instanceof - natanfelles - 01-26-2021 LN_Account has the proper use call in the model? RE: Accessing a custom object with instanceof - baxterheinen - 01-26-2021 The specific error is: Class 'LN_Account' not found The model is like this: PHP Code: namespace App\Models; LN_Account is in app\Libraries PHP Code: namespace App\Libraries; if I print_r $credentials inside the model/method I get this, so the controller knows what it is and created it. PHP Code: App\Libraries\LN_Account Object Okay so the outer if ($account instanceof LN_Account) seems to work now, it's this that doesn't: $credentials = $query->getCustomRowObject(0, 'LN_Account') Do I have to instantiate a new LN_Account() for it to use? I figured it would do it automatically. RE: Accessing a custom object with instanceof - iRedds - 01-26-2021 (01-26-2021, 06:18 PM)baxterheinen Wrote: The specific error is: Class 'LN_Account' not found 15 years Of course you will get an error. PHP Code: //use RE: Accessing a custom object with instanceof - baxterheinen - 01-26-2021 (01-26-2021, 06:34 PM)iRedds Wrote:(01-26-2021, 06:18 PM)baxterheinen Wrote: The specific error is: Class 'LN_Account' not found Ah, because it's not already an object, got it. (01-26-2021, 06:37 PM)baxterheinen Wrote:(01-26-2021, 06:34 PM)iRedds Wrote:(01-26-2021, 06:18 PM)baxterheinen Wrote: The specific error is: Class 'LN_Account' not found RE: Accessing a custom object with instanceof - iRedds - 01-26-2021 (01-26-2021, 06:37 PM)baxterheinen Wrote: Ah, because it's not already an object, got it. Incorrect example in the documentation. The documentation uses the User class without a namespace, so just 'User' is passed as a parameter. If the class uses a namespace, then it must also be specified. RE: Accessing a custom object with instanceof - InsiteFX - 01-27-2021 This is from PHP.net. Code: If you want to test if a classname is an instance of a class, the instanceof operator won't work. |