Static Variable Variables

<?php
  class A {
    static function b() {
      echo "It works\n";
    }
  }
  $theClass = "A";
  $x = new $theClass;

  /* Are any of the following legal? Which? */

  A::b();
  $x->b();
  $theClass::b();
?>

Answer: A::b() and $x->b() are legal, $theClass::b() is not.

Comments

One response to “Static Variable Variables”

  1. RW Avatar
    RW

    Have you actually tried running this? All three work. =b

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.