So I have a task to access an external api and then render the results to a separate FE. I have made an ApiClass and a ProductListClass. Then from an index page I am including the two class files and …
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
PHP – constructor with SQL query [closed]
Option 1: query the data first and then pass the data to the constructor Option 2: use the constructor to query the data and then fill the properties Option 1 Example $val1 = 1; $query = mysql_query(&…
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.
How to dynamically add elements to the array value of an SplObjectStorage object
Suppose we have an Index class: class Index{ /* indexing fields */ public $id ; public $word; /* Constructor */ public function __construct($id, $word) { $this->…
PHP – Accessing a object property from dynamic variable
I’m looking for accessing a property of a object property of an object like this : $property = “user->name”; echo $object->$property; // ??, I want $object->user->name I tried a lot of …
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