Does constructor return values?

No, in PHP constructor does not return values. If we try to return values from a class constructor it will not return that. Lets consider the following class:
class Cars {
  function __construct($params) {
    return is_numeric($params) ? "true" : "false"; 
  }
}
Now if we try to instantiate the above class it will not return any value.
$obj = new Cars(10);
print_r($obj);

Output

Cars Object
(
)
But if we want to call the constructor explicitly then we can do it but that is not recommended. See the example below:
$obj = new Cars(100);
echo $obj->__construct(100);

Output

true

Comments