We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

PHP7 + Static Function

Can I still use static function in PHP7+Phalcon3 ? (This worked fine in PHP5+Phalcon2)

For example, I would like to have /libraries/Test.php file with static functions.

Test.php Class: class Test {

function foobar() { echo 'Test'; }

}

Then simply call it like this in controller or model;

use MyApp\Libraries\Test;

Test::foobar();



5.4k

Yes, you can.

Nothing changed with static functions in php 7.

I'm using a lot of them in my projects php7+phalcon 3.0.x, for example

User\Authorize::isAuthorized()



2.3k

Do you have to use namespace in place like that ? In PHP5 I used to be able to do something like Authorize::isAuthorized()



5.4k

Do you have to use namespace in place like that ? In PHP5 I used to be able to do something like Authorize::isAuthorized()

You can use both ways, same as in php5

Don't you get E_STRICT message with such syntax?

Strict standards: Non-static method Class::Method() should not be called statically in /path/to/your/app/index.php on line XX

I prefer to use static keyword when I really need static methods.

PHP is dynamic language though :)