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();



2.7k

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()



821

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



2.7k

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 :)