Aşağıdaki kodda ben Tür Dayatma sahip olduğu (bir yapıcı olur) bir işlevi çağırın. Ben kodu çalıştırdığınızda aşağıdaki hatayı alıyorum:
Catchable fatal error: Argüman 1 () question.php {satırı on line 3 run.php denilen ve tanımlanmış, belirli bir dize, dize bir örneği olmalıdır __construct :: Soru geçti [ (2)]}
Ne söyleyebilirim gelen hata işlevi bir dize bekliyor ama bir dizge olduğunu bana anlatıyor. Neden geçirilen dize kabul etmiyor?
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;
}
}
?>