Skip to content

Commit

Permalink
Compile starts/ends with using PHP8 functions str_starts/ends_with
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Oct 21, 2023
1 parent 51cfad8 commit 30b5a56
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Node/Expression/Binary/EndsWithBinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function compile(Compiler $compiler): void
->subcompile($this->getNode('left'))
->raw(sprintf(') && is_string($%s = ', $right))
->subcompile($this->getNode('right'))
->raw(sprintf(') && (\'\' === $%2$s || $%2$s === substr($%1$s, -strlen($%2$s))))', $left, $right))
->raw(sprintf(') && str_ends_with($%1$s, $%2$s))', $left, $right))
;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Node/Expression/Binary/StartsWithBinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function compile(Compiler $compiler): void
->subcompile($this->getNode('left'))
->raw(sprintf(') && is_string($%s = ', $right))
->subcompile($this->getNode('right'))
->raw(sprintf(') && (\'\' === $%2$s || 0 === strpos($%1$s, $%2$s)))', $left, $right))
->raw(sprintf(') && str_starts_with($%1$s, $%2$s))', $left, $right))
;
}

Expand Down

0 comments on commit 30b5a56

Please sign in to comment.