Nesting an anonymous class within another class does not give it access to
any private or protected methods or properties of that outer class. In order
to use the outer class' protected properties or methods, the anonymous class
can extend the outer class. To use the private properties of
the outer class in the anonymous class, they must be passed through its
constructor:

public function getValue() {// do some operationreturn 'some returned value'; }

public function getValueWithArgu($str) {// do some operationreturn 'returned value is '.$str; } };}

echo "\n";

var_dump($ano_class_obj_with_func);echo "\n";

echo $ano_class_obj_with_func->prop1;echo "\n";

echo $ano_class_obj_with_func->prop2;echo "\n";

echo $ano_class_obj_with_func::SETT;echo "\n";

echo $ano_class_obj_with_func->getValue();echo "\n";

echo $ano_class_obj_with_func->getValueWithArgu('OOP');echo "\n";

echo "\n";

// Third way - passing argument to anonymous class via constructors$arg = 1; // we got it by some operation$config = [2, false]; // we got it by some operation$ano_class_obj_with_arg = ano_func_with_arg($arg, $config);

Anonymous classes are syntax sugar that may appear deceiving to some.The 'anonymous' class is still parsed into the global scope, where it is auto assigned a name, and every time the class is needed, that global class definition is used. Example to illustrate....