Petr Cezar
Petr Cezar

Reputation: 159

Cake or PHP feature or bug?

I'm a PHP greenhorn, so please be patient with me, but I've just bumped into something I don't understand. I have PHP 5.3 and CakePHP 1.3.10.

I have a Helper called Phone with method formPhoneNum(). When I call, in my view, this:

echo $this->Phone->formPhoneNum('+420111222333');

everything works all right. When I call this:

$Phone = '+420111222333';
echo $this->Phone->formPhoneNum($Phone);

everything works all right as well. But, when I call this:

$phone = '+420111222333';
echo $this->Phone->formPhoneNum($phone);

I get this:

Fatal error: Call to a member function formPhoneNum() on a non-object in .../view.ctp on line 3

Isn't that cool? :-D

Upvotes: 1

Views: 123

Answers (1)

Dunhamzzz
Dunhamzzz

Reputation: 14808

Any helper you create is available from both $this->helperName and $helperName, when you assign $phone = '', you are overwriting the PhoneHelper. This is behaviour won't exist in 2.0 and you will only be able to use $this->helperName.

Upvotes: 5

Related Questions