0
任何人都可以解釋爲什麼這段代碼不起作用(內容$this->_string
)是空的嗎?PHP方法鏈接
<?php
class WordProcessor
{
public $_string = '';
public function __constructor($text)
{
$this->_string = $text;
}
public function toLowerCase()
{
$this->_string = strtolower($this->_string);
return $this;
}
public function trimString()
{
echo $this->_string;
$this->_string = trim($this->_string);
return $this;
}
public function capitalizeFirstLetter()
{
$this->_string = trim($this->_string);
return $this;
}
public function printResult()
{
echo $this->_string;
}
}
$data = new WordProcessor("here Are some words! ");
$data->trimString()->toLowerCase()->capitalizeFirstLetter()->printResult();
+1良好的漁獲物和是第一個發現它,重複的答案如下:) – Sarfraz