Code
<?php
$d='ddd';
class Cl {
private $d;
public function __construct(){
global $d;
$this->d = $d;
}
//option 1
public function getData() {
return $this->d;
}
//option 2
public function getDataV2() {
return $GLOBALS['d'] ?? NULL;
}
}
$c = new Cl();
var_dump($c->getData());
var_dump($c->getDataV2());
Note what r4f said, in general you should not use globals anywhere in your code.