Passing single object vs. passing multiple parameters

Method A (naked parameters) always has the advantages that it requires the method author to type less, since they don’t have to implement a Parameter Object, it requires the method caller to type less, since they don’t have to instantiate a Parameter Object it performs better, since no Parameter Object has to be constructed and … Read more

Check if returned value is not null and if so assign it, in one line, with one method call

Same principle as Loki’s answer but shorter. Just keep in mind that shorter doesn’t automatically mean better. dinner = Optional.ofNullable(cage.getChicken()) .orElse(getFreerangeChicken()); Note: This usage of Optional is explicitly discouraged by the architects of the JDK and the designers of the Optional feature. You are allocating a fresh object and immediately throwing it away every time. … Read more

How to get name of calling function/method in PHP? [duplicate]

The simplest way is: echo debug_backtrace()[1][‘function’]; As noted in the comments below, this can be further optimized by passing arguments to: omit both the object and args indices limit the number of stack frames returned echo debug_backtrace(!DEBUG_BACKTRACE_PROVIDE_OBJECT|DEBUG_BACKTRACE_IGNORE_ARGS,2)[1][‘function’];