I was wondering is it bad practice (I'm assuming it is) to do something like this, in PHP? Common sense tells me this could lead to UB, but I haven't been able to find a reference to this in the manual, or elsewhere.
<?php
class A
{
public function __construct(){}
}
class B extends A
{
public function __construct()
{
global $d;
$d = new C; // How wrong is it to replace the value of $d from inside B, like this?
exit();
}
}
class C extends A
{
public function __construct()
{
echo 'C';
}
}
$d = new B;
Output: C
I'd like to know the risks (if any) that come with executing code like this, and would especially appreciate a link to the manual that talks about doing something like this.
Or (since this simple code runs without errors), is this code valid, but just considered a bad practice?