Phalcon模型不接受变量

I have a trouble when i try to verify if a user exists in the database.

$login = $this->cookies->get('login');
$loggedinas = $login->getValue();
$user = Users::findFirstByUsername($loggedinas)

This returns:

PHP Notice:  Trying to get property of non-object in /public_html/app/views/charactersheets/create.phtml on line 27, referer: localhost/charactersheets

However if i use this:

$user = Users::findFirstByUsername("pentacore")

it works, and i've checked so that the cookie contains the right username with var_dump($loggedinas) (returns string(32) "pentacore", thank you silkfire) which returned pentacore so... what could be the problem?

From Phalcon @ Phalcon Framework Forum:

It could be that cookie's decryption adds extra trailing spaces so you have to probably do:

$login = $this->cookies->get('login');
$loggedinas = trim($login->getValue());
$user = Users::findFirstByUsername($loggedinas)