FreiChat related discussions
what does the php code in main.php mean?

Approximate line number 62 in main.php:

$sessions = new $this->driver($this->db);


1) Is driver() any method? where is it defined?

2)new $this->driver -- i cannot make anything out of it . What is the explanation from the programming view ?



I am using custom installation

Thanks in advance

Approximate line number 62 in main.php: $sessions = new $this->driver($this->db); 1) Is driver() any method? where is it defined? 2)new $this->driver -- i cannot make anything out of it . What is the explanation from the programming view ? I am using custom installation Thanks in advance

driver is a variable defined in the arg.php file. we use it to call the constructor.
the code there creates a new object of the custom/selected driver class.

driver is a variable defined in the arg.php file. we use it to call the constructor. the code there creates a new object of the custom/selected driver class.
Necessity is the mother of all inventions!

$sessions = new $this->driver($this->db);

if driver is a variable defined in arg.php, how could it take an argument i.e. $this->db ?

Explanation of the syntax please

$sessions = new $this->driver($this->db); if driver is a variable defined in arg.php, how could it take an argument i.e. $this->db ? Explanation of the syntax please

we use the concept called dynamic binding.
when the PHP parser finds the below code.

$sessions = new $this->driver($this->db);

"$this->driver" is replaced with its value.
so if a "Custom" driver is selected.
ie. if $this->driver="Custom".
The code above is then equivalent to the following code,
$sessions = new Custom($this->db);

we use the concept called dynamic binding. when the PHP parser finds the below code. <code> $sessions = new $this->driver($this->db); </code> "$this->driver" is replaced with its value. so if a "Custom" driver is selected. ie. if $this->driver="Custom". The code above is then equivalent to the following code, <code> $sessions = new Custom($this->db); </code>
Necessity is the mother of all inventions!
77
3
0
live preview
enter atleast 10 characters
WARNING: You mentioned %MENTIONS%, but they cannot see this message and will not be notified
Saving...
Saved
With selected deselect posts show selected posts
All posts under this topic will be deleted ?
Pending draft ... Click to resume editing
Discard draft