Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

12
  • 76
    @RobinvanBaalen Actually, it can improves code readability. Also, downvotes are supposed to be for (very) bad answers, not for "neutral" ones. Commented Jul 9, 2013 at 8:56
  • 41
    @RobinvanBaalen functions are nearly by definition for readability (to communicate the idea of what you're doing). Compare which is more readable: if ($email->contains("@") && $email->endsWith(".com)) { ... or if (strpos($email, "@") !== false && substr($email, -strlen(".com")) == ".com") { ... Commented Jul 25, 2013 at 12:12
  • 3
    @RobinvanBaalen in the end rules are meant to be broken. Otherwise people wouldn't come up with newer inventive ways of doing things :) . Plus have to admit I have trouble wrapping the mind around stuff like on martinfowler.com. Guess the right thing to do is to try things out yourself and find out what approaches are the most convenient. Commented Aug 22, 2013 at 1:43
  • 6
    Another opinion: Having an utility function which you can easily wrap can help debugging. Also it loundens the cry for good optimizers which eliminate such overhead in production services. So all opinions have valid points. ;) Commented Feb 20, 2014 at 21:09
  • 20
    Of course this is usefull. You should encourage this. What happens if in PHP 100 there is a new and faster way to find string locations ? Do you want to change all your places where you call strpos ? Or do you want to change only the contains within the function ?? Commented Jun 17, 2015 at 9:44