Skip to content

Tag: oop

How to use PDO::FETCH_CLASS with __set() method?

I want to create an object right after fetching data from my database. For that I’m using PDO::FETCH_CLASS and a rewritten __set() method that I’ve put in a trait. However, I can’t figure out why I have an error mentionning : “Fatal error: Uncaught ArgumentCountError: Too few arguments…

PHP PDO to create an object of a class with fetchObject

I am trying to create a “User” object inside my class “User” based on the properties I have stored inside my database, which I use PDO to connect to. I’ve search some pages on Google and found that most people use the fetchObject method for that. Right now, I am trying to use thi…

PHP method scope binding

I am confused by how PHP call method in parent-children hierarchy. Here is the code class A { private function foo() { echo “A!”; } public function test() { …

Set a variable of a class in another class

I have a class address_book in which I want to set $DBConnection using method from another class: Another class: So var_dum should return ‘1’ as it has to be assigned to protected $DBConnection; in the first class. I’m starting my learning of PHP OOP so probably everything is bad. Any way it…

Laravel container and shared instances

I am wondering how Laravel differentiates between singletons(shared instances) and concrete implementations that might be overwritten inside the container. The container has a bind method that looks like this: It also has a singleton method that calls this function but with the $shared argument always being t…