Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Приоритет операторов -- возможная ошибка #62

Open
KarelWintersky opened this issue Jan 21, 2019 · 0 comments

Comments

@KarelWintersky
Copy link

https://github.com/emuravjev/mdash/blob/master/src-php/EMT.Lib.php#L200

$text = preg_replace_callback('/(\<\/?)([^<>]+?)(\>)/s', create_function('$m','return (strlen($m[1])==1 && substr(trim($m[2]), 0, 1) == \'-\' && substr(trim($m[2]), 1, 1) != \'-\')? $m[0] : $m[1].( substr(trim($m[2]), 0, 1) === "a" ? "%%___"  : ""  ) . EMT_Lib::encrypt_tag(trim($m[2]))  . $m[3];'), $text);

Без create_function() это раскрывается в:

$text = preg_replace_callback('/(\<\/?)([^<>]+?)(\>)/s', function ($m) {
                return
                    (strlen($m[1])==1 && substr(trim($m[2]), 0, 1) == '-' && substr(trim($m[2]), 1, 1) != '-') ? $m[0] : $m[1]
                    .
                    ( substr(trim($m[2]), 0, 1) === "a" ? "%%___"  : ""  )
                    .
                    EMT_Lib::encrypt_tag(trim($m[2]))
                    .
                    $m[3];
            }, $text);

что вообще выглядит как ошибка: приоритет тернарного оператора ?: ниже оператора . и этот код выполняется как:

(strlen($m[1])==1 && substr(trim($m[2]), 0, 1) == '-' && substr(trim($m[2]), 1, 1) != '-') 

? $m[0] 

: ( $m[1] . ( substr(trim($m[2]), 0, 1) === "a" ? "%%___"  : ""  )... ) ;

То есть либо $m[0] либо склеенная строка.

Все правильно?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant