Skip to content

Instantly share code, notes, and snippets.

@ironsmile
Last active August 29, 2015 14:08
Show Gist options
  • Save ironsmile/533a5f6aaecb04d27b68 to your computer and use it in GitHub Desktop.
Save ironsmile/533a5f6aaecb04d27b68 to your computer and use it in GitHub Desktop.
Do you spot the bug?
<?php
$string = 'lalalalala';
$string = preg_replace('/(a+)/', 'many-a', $string);
// continue my work with string
// hopefully it is "lmany-almany-almany-almany-almany-a"
?>
<?php
$string = 'lalalalala';
$preg_ret = preg_replace('/(a+)/', 'many-a', $string);
if ($preg_ret === null) {
throw new Exception("Preg replace did an error: ", preg_last_error());
}
$string = $preg_ret;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment