Dup Goto 📝

PhpAnonymousClasses

PT2/aw/lang/php 07-31 13:46:41
To Pop
32 lines, 77 words, 440 chars Monday 2023-07-31 13:46:41

Importing classes without name clashes

<?php
# if p1 and p2 define functions of the same name, is there a clash
# if we include in function scope?
function f1() {
  include("p1.php");
  $g->f();
}
function f2() {
  include("p2.php");
  $g->f();
}
f1();
f2();
<?php
$g = new class {
  function f() {
    echo "hello world\n";
  }
};
<?php
$g = new class {
  function f() {
    echo "goodbye sir\n";
  }
};