can you have more than one constructor in class php
WORK AROUND
<?php
class Animal
{
public function __construct()
{
$arguments = func_get_args();
$numberOfArguments = func_num_args();
if (method_exists($this, $function = '__construct'.$numberOfArguments)) {
call_user_func_array(array($this, $function), $arguments);
}
}
public function __construct1($a1)
{
echo('__construct with 1 param called: '.$a1.PHP_EOL);
}
public function __construct2($a1, $a2)
{
echo('__construct with 2 params called: '.$a1.','.$a2.PHP_EOL);
}
public function __construct3($a1, $a2, $a3)
{
echo('__construct with 3 params called: '.$a1.','.$a2.','.$a3.PHP_EOL);
}
}
$o = new Animal('sheep');
$o = new Animal('sheep','cat');
$o = new Animal('sheep','cat','dog');
// __construct with 1 param called: sheep
// __construct with 2 params called: sheep,cat
// __construct with 3 params called: sheep,cat,dog
Also in PHP:
- base 64 decode in php
- combine two query value in laravel 8
- ** (process:82385): CRITICAL **: 22:54:20.169: string_replace: assertion 'self != NULL' failed
- check if string contains word
- ( ! ) Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 20480 bytes) in /Users/chakma/demo/vokuro/app/controllers/UsersController.php on line 375
- clear catche laravel
- echo child category
- count php string
- check type of var in php
- date today in php
- clean redis cache
- LARAVEL DISABLE LOGIN REGISTER ROUTEA
- How to add validation form image in laravel
- $_SESSION php example
- display error php linux
- crrate model in laravel
- arr::plunk laravel
- array push object php
- enable the cache mechanisms laravel
- display error php
- date 'F' what is it
- date_default_timezone_set("America/New_York"); echo "The time is " . date("h:i:sa");
- echo date in php
- create model, controller and migration in single command laravel