DEV Community

Discussion on: April 15 — Daily CodeNewbie Check-in Thread

Collapse
 
ekafyi profile image
Eka • Edited

Hi all! I've been off social media for a while (still peep at Discord though 😬), so have not been interacting much with dev communities. Grateful for this brilliant thread, thank you CodeNewbie & DEV!

Quite swamped with work these days; aside of day job I'm taking a short-term side gig this week, grateful but kind of drained. Unfortunately it also means I don't have the energy for personal projects and/or learning after some 8 + 3 hours of work!

Quick snippet of random stuff that tripped me up at day job where I work with Laravel (this applies to PHP in general though): We call static and public methods differently. 😶

// Define the methods
class Foo {
  public function doSomething() { /* something */ };

  static function doOtherThing() { /* other thing */ };
}

// Call the methods from elsewhere
use Foo; // regardless of method type, make sure you call the class

// Call public method
$foo = new Foo();
$foo-> doSomething();

// Call static method
Foo:: doOtherThing();

If you copy-paste from one file/class to another without paying attention to that, you'll get 💀 aaaall the errors 💀.

You can also have private methods and... public static function (what the? 😆) but today I'm mainly learning to differentiate those two. Mind you I'm not strong at PHP, started from front-front-end (HTML, CSS, presentational JS) so I'm learning as I go.

Anyway hope you all have a good day!