douhao1956 2012-06-04 12:18
浏览 24
已采纳

PHP方法链接

Can anyone explain me why this code does not work (the content $this->_string) is empty?

<?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();
  • 写回答

2条回答 默认 最新

  • doulangdang9986 2012-06-04 12:20
    关注

    Use construct instead of constructor?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?