I apologize for my bad English, I used Google translate. I would propose developers to add the ability to use the classes in the type conversion, adding in class a new magical method, for example, __converting()
For example: <?php class ClassName { private $myProperty; public function __construct($value) { $this->myProperty = $value; } public function show() { echo $this->myProperty; } // magical method public function __converting($value) { return new self($value); } } // Example of use $value = 123; $value = (ClassName)$value; $value->show(); // Result: 123 ?> Similarly, for the classes in the namespace: <?php /* A class declaration in namespace: MyNamespace\ClassName */ $value = 123; $value = (MyNamespace\ClassName)$value; // Or $value = (\MyNamespace\ClassName)$value; $value->show(); // Result: 123 ?> Thank you for your attention.