N
N
Nentra2022-02-21 11:09:24
Bitrix24
Nentra, 2022-02-21 11:09:24

Why do a module connection check if I want to connect it anyway?

Why do a module connection check if I want to connect it anyway?

if(CModule::IncludeModule("socialnetwork"))
      { 
        //здесь можно использовать функции классов модуля socialnetwork
      }


If I connect the socialnetwork module like this , everything will break, stop working and start to slow down terribly?
CModule::IncludeModule("socialnetwork")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2022-02-21
@Nentra

We open the documentation and see:

Returns "true" if the module is installed, "false" otherwise.

In other words, calling this function does not guarantee that the module will be successfully connected. And that's it in order to make sure that he is connected and add a check.
In your example, everything will work as long as everything is fine. But as soon as an error occurs when connecting the module, special effects will begin associated with calling non-existent functions, accessing non-existent classes, etc. While in the variant with if, this fragment will simply turn off and that's it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question