Answer the question
In order to leave comments, you need to log in
Return in PHP constructor?
There is a code:
class GetInfo {
public $name;
function __construct($name) {
$this->name = $name;
$name = strtoupper($name);
return $name;
}
}
$a = new GetInfo('Ivan');
...
Answer the question
In order to leave comments, you need to log in
You need __toString
class GetInfo
{
public $name;
function __construct($name)
{
$this->name = strtoupper($name);
}
function __toString()
{
return $this->name;
}
}
$a = new GetInfo('Ivan');
// ...
The constructor does not return a value.
Signature:
Read php.net/manual/ru/language.oop5.decon.php
If you really want to: https://3v4l.org/iOpXcecho $a->__construct('Ivan');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question