Configuration object Pattern in PHP

The name of the picture


Configuration object Pattern in PHP



I am trying to understand what Configuration Object pattern is. For instance in php, how to write the following class using Configuration Object pattern?


class User extends People {
public function __construct($name , $email){}
}





You can check good documentation here ibm.com/developerworks/library/os-php-config/index.html
– SynapseIndia
6 hours ago




1 Answer
1



Like this:


class User extends People {
private $name;
private $email;

public function __construct($conf){
$this->name = $conf->name;
$this->email = $conf->email;
}
}



Of course this pattern is for much more complicated situations, when you want to configure DB connection or some API client or smth like that. This pattern is helpful, when you need pass many properties or do some actions with them.



I think here's good article about this pattern: https://code.tutsplus.com/tutorials/whats-a-configuration-object-and-why-bother-using-it--active-11580






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Stripe::AuthenticationError No API key provided. Set your API key using “Stripe.api_key = ”

CRM reporting Extension - SSRS instance is blank

Keycloak server returning user_not_found error when user is already imported with LDAP