Skip to content
Advertisement

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 to function Banner::__construct(), 0 passed and exactly 1 expected in D:Logicielswamp64wwwprojet-4writer-blogentityBanner.php on

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 this to create an object of this

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 has to work like this. In first class

Get class name minus namespace without using Reflection

Is there a simple way to get the class name without the namespace without using Reflection? This is my class and when I call get_class() I get CRMPiccoBundleServicesRFCWebhookSiteCancelled Answer Or simply exploding the return from class_name and getting the last element: Or simply removing the namespace from the output of get_class: Either works with or without namespace. And so on.

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 true like so: The difference here being that although they both are bound in

Advertisement