0

谁能解释我为什么这段代码不起作用(内容$this->_string)是空的?

<?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();
4

2 回答 2

5

使用construct而不是constructor

于 2012-06-04T12:20:41.003 回答
0

它的

public function __construct($text)

不是__constructor(..)

于 2012-06-04T12:22:34.230 回答