This is nothing to do with "nested" functions, and calling a function from another to reuse code is indeed the whole point of using functions in the first place.
Your problem is that selectMediaIds
is not a global function, but a private method of the class MediaManager
- it is "part of" that class, and can reference the current instance of the class under the magic variable $this
.
In order to call such a method, you have to call it using the object->method
notation, so you need to use $this->selectMediaIds($object)
. That tells PHP that you want to call selectMediaIds
within that particular object $this
, which you know is an instance of class MediaManager
.
This is the same operation as you are using with your DB call when you write $req->fetch();