E
E
Evgen2015-10-03 19:58:36
PHP
Evgen, 2015-10-03 19:58:36

How to deal with static class properties in PHP?

Hello!
I'm a little confused about the static properties of the class.
I am implementing one thing for Bitrix. So. There, when updating an information element, it is necessary to change the property values ​​when it is updated, which, in turn, leads to a call to the same update procedure.
Some kind of flag could be used as a "preventor", which would say that we called the procedure a second time, we do not need to execute it.
It turned out something like this:

class UserHandlers
    {
        static $disableHandlerForUpdateOther = false;

        //UPDATE ACTION
        public static function OnAfterIBlockElementUpdateHandler(&$arFields) {          
        if (!self::$disableHandlerForUpdateOther) {
               ...
               self::$disableHandlerForUpdateOther = true;
               ...
        }

Do I understand correctly that if several elements are updated simultaneously in parallel, the situation will turn out that $disableHandlerForUpdateOther will probably have the value true at the beginning of the OnAfterIBlockElementUpdateHandler method execution?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Khomenko, 2015-10-05
@EASemashko

Do I understand correctly that if several elements are updated simultaneously in parallel , the situation will turn out that $disableHandlerForUpdateOther will probably have the value true at the beginning of the OnAfterIBlockElementUpdateHandler method execution?

There will be no parallel execution within a single request. The calls will come in sequence. The first call will evaluate to false and execute the contents of the method. The rest will be true and will not be able to do anything.
A long and clear name is much better than a short and incomprehensible one. The main idea is that the name of the method/variable fully explains its content/task.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question