Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Problem on detecting return type-hint when running try catch

Hi all

I have a problem when I add return type hints, here my code

    /**
     * Create a message and send it.
     * Returns false on error - Use the ErrorInfo variable to view description of the error.
     * 
     * @return bool
     */
    public function send() ->boolean
    {
        var e;
        try {
            if !this->preSend()  {
                return false;
            }
            //return this->postSend();
        } catch Exception, e {
            let this->_mailHeader = "";
            this->setError(e->getMessage());
            if this->_exceptions === true {
                throw e;
            }
            return false;
        }
    }

When running zephir compile it, i get error

Zephir\CompilerException: Reached end of the method without returning a valid type specified in the return-type hints in /home/duythien/github/cphalcon/phalcon/mail/adapter/mail.zep on line 144

        {
    ----^

What is problem that ?

I think It's a bug in Zephir Core



1.8k
Accepted
answer

All branches must return a valid type:

public function send() ->boolean
{
        var e;
        try {
            if !this->preSend()  {
                return false;
            }
            //return this->postSend();
        } catch Exception, e {
            let this->_mailHeader = "";
            this->setError(e->getMessage());
            if this->_exceptions === true {
                throw e;
            }
            return false;
        }
        return true;
}


1.2k
edited Oct '14

@Phalcon

Yeah, that working