Y
Y
Yaroslav2017-11-15 23:08:39
PHP
Yaroslav, 2017-11-15 23:08:39

What could be the problem in DLE 10.6 + PHP7 with the check_module function in which preg_replace_callback is called in the regex passed not-aviable?

Good day.
The following code [not-aviable=faq]smth[/not-aviable] is called in the main.tpl template file and it works correctly on php 5.6. Further, the site is transferred to php 7 and the template becomes simply empty. After a long search, I came to the conclusion that if you remove all references to [not-aviable], the site starts working correctly.
We climb deeper, namely, we find the check_module method in templates.class.php and see the following code there:

function check_module($matches) {
    global $dle_module;
    
    $regex = '/\[(aviable|available|not-aviable|not-available)=(.+?)\]((?>(?R)|.)*?)\[\/\1\]/is';

    if (is_array($matches)) {
      
      $aviable = $matches[2];
      $block = $matches[3];
      
      if ($matches[1] == "aviable" OR $matches[1] == "available") $action = true; else $action = false;
      
      $aviable = explode( '|', $aviable );
      
      if( $action ) {
        
        if( ! (in_array( $dle_module, $aviable )) and ($aviable[0] != "global") ) $matches = '';
        else $matches = $block;
      
      } else {
        
        if( (in_array( $dle_module, $aviable )) ) $matches = '';
        else $matches = $block;
      }		
  
    }
  
    return preg_replace_callback($regex, array( &$this, 'check_module'), $matches);
  }

We remove not_aviable from the $regex variable and the site starts working, accordingly [not-aviable] is displayed as plain text and the template engine ignores it.
The question is, why does this work correctly in php 5.6, but not in php 7? I'm not a big connoisseur of regular expressions and the intricacies of functions, but here specifically preg_replace_callback, in php 7.
It became very interesting...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question