find_prologue_end( $code ); if ( 0 === $offset ) { return " $token ) { $offset += strlen( is_array( $token ) ? $token[1] : $token ); if ( $in_statement ) { if ( '{' === $token ) { // Block syntax: the guard belongs inside the braces. $end = $offset; break; } if ( ';' === $token ) { $end = $offset; $in_statement = false; } continue; } $id = is_array( $token ) ? $token[0] : null; if ( in_array( $id, $skipped, true ) ) { continue; } if ( T_DECLARE === $id || $this->is_namespace_declaration( $tokens, $index ) ) { $in_statement = true; continue; } break; } return max( 0, $end - strlen( $open_tag ) ); } /** * Check whether a token opens a namespace declaration. * * `namespace\my_function()` uses the same keyword as an operator, and must * not be mistaken for a declaration. * * @param array $tokens Token list. * @param int $index Token to test. * * @return bool */ private function is_namespace_declaration( array $tokens, int $index ): bool { if ( ! is_array( $tokens[ $index ] ) || T_NAMESPACE !== $tokens[ $index ][0] ) { return false; } $count = count( $tokens ); for ( $next = $index + 1; $next < $count; $next++ ) { if ( is_array( $tokens[ $next ] ) && T_WHITESPACE === $tokens[ $next ][0] ) { continue; } return ! is_array( $tokens[ $next ] ) || T_NS_SEPARATOR !== $tokens[ $next ][0]; } return false; } }