0

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 Answers 2

5

Use construct instead of constructor?

Sign up to request clarification or add additional context in comments.

1 Comment

+1 good catch and being the first one to spot it, duplicate answers following :)
0

Its

public function __construct($text)

not __constructor(..)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.