Hello, inside the class there is a config task:
public $config = array( 'api_key' => '8a29125664722e968987b085cf3a', 'offer_id' => $offer_id, 'user_id' => 3291, ); Swears on the line with offer_id. What could be the problem?
Hello, inside the class there is a config task:
public $config = array( 'api_key' => '8a29125664722e968987b085cf3a', 'offer_id' => $offer_id, 'user_id' => 3291, ); Swears on the line with offer_id. What could be the problem?
Class fields cannot be initialized with non-constant expressions.
You can pass the desired value to a class method or to a constructor.
class A { public $config = array( 'api_key' => '8a29125664722e968987b085cf3a', 'offer_id' => null, 'user_id' => 3291, ); public function __construct($offer_id) { $this->config['offer_id'] = $offer_id; } } But much better:
class A { private $config; public function __construct($config) { $this->config = $config; } } I would solve this problem like this.
public function setConfigOffer($id){ if($id) $this->config['offer_id']=$id; else return false; } and I would cross out this line - in my opinion it contradicts my ideas about creating classes
Source: https://ru.stackoverflow.com/questions/639677/
All Articles
$offer_idvariable and the class modifiers. - rjhdby