Nel codice seguente chiamo una funzione (capita di essere un costruttore) in cui ho il suggerimento del tipo. Quando eseguo il codice ottengo il seguente errore:Errore durante il passaggio di una stringa nel metodo con tipo hinting
catturabile errore fatale: Argomento 1 passata alla domanda :: __ construct() deve essere un esempio di stringa, stringa data, chiamato in run.php sulla linea 3 e definito question.php on line
Da quello che posso dire l'errore mi sta dicendo che la funzione si aspetta una stringa, ma è stata passata una stringa. Perché non accetta la stringa passata?
run.php:
<?php
require 'question.php';
$question = new Question("An Answer");
?>
question.php:
<?php
class Question
{
/**
* The answer to the question.
* @access private
* @var string
*/
private $theAnswer;
/**
* Creates a new question with the specified answer.
* @param string $anAnswer the answer to the question
*/
function __construct(string $anAnswer)
{
$this->theAnswer = $anAnswer;
}
}
?>
È perché scalari sono tutti massaggiati l'uno nell'altro a seconda delle necessità in PHP, in modo da 0 == false, ecc Come ad esempio, non è possibile digitare suggerimento uno scalare. È causa di molte discussioni sugli interni di PHP, di cui sono membro. – Fuser97381