Skip to content

Instantly share code, notes, and snippets.

Avatar
😴
Sleeping

Eric McWinNEr EricMcWinNer

😴
Sleeping
View GitHub Profile
View Example.php
<?php
class A {
public static function iAm() {
return "A";
}
}
// echo A::iAm(); // "A"
View Example.php
<?php
class A {
private function foo() {
echo "success!\n";
}
public function test() {
static::foo();
}
}
View Example.php
<?php
class Animal {
public static function makeSound(){
echo "Animal";
}
public static function vocalize() {
echo static::makeSound();
}
View Example.php
<?php
class Animal {
public static function makeSound(){
echo "Animal";
}
public static function vocalize() {
echo self::makeSound();
}
View Example.php
<?php
class A {
public function nonStaticMethod(){
echo "I am non-static";
}
public static function staticMethod() {
echo "I am static" . self::nonStaticMethod(); // Throws error: Non-static method cannot be called statically
}
View Example.php
<?php
class A {
public static function staticMethod() {
echo "I am static";
}
public function nonStaticMethod() {
echo "I am not static" . self::staticMethod(); // This works nicely.
}
View Example.php
<?php
class A {
public function staticMethod() {
echo get_class($this);
}
public function otherStaticMethod() {
self::staticMethod(); // This runs nicely. We can use self:: to access static methods from other static methods.
}
View Example.php
<?php
class Animal {
public static function makeSound(){
echo "Animal";
}
public static function vocalize() {
echo self::makeSound();
}
View UserController.php
<?php
namespace App\Http\Controllers\Employer\Dashboard;
use App\Http\Controllers\Controller;
use App\Models\User;
class HomeController extends Controller
{
View User.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
/**
* The booted method of the model