2012-06-04 2 views
0

Может ли кто-нибудь объяснить мне, почему этот код не работает (содержимое $this->_string) пусто?PHP метод chaining

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

ответ

5

Использование construct вместо constructor?

+0

+1 хороший улов и быть первый, чтобы обнаружить его, дублировать ответы следующий :) – Sarfraz

Смежные вопросы