A Little Noise

15Nov/050

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();
?>

Show Answer ▼

Filed under: PHP Gotchas No Comments
14Nov/050

Form Names

Given the following page:

<form>
  <input type="radio" name="BT.123" value="active" />
  <input type="radio" name="BT.123" value="inactive" />
  <input type="submit" value="Submit" />
</form>

<?php
  echo "GET: ", $_GET['BT.123'];
  echo "POST: ", $_POST['BT.123'];
  echo "REQUEST: ", $_REQUEST['BT.123'];
?>

Assume the "inactive" button is checked and the form is submitted. What is the output?
Show Answer ▼

Filed under: PHP Gotchas No Comments
12Nov/050

Post increment

<?php
$a = 4;
echo $a+++$a++;
?>

What is the output?
Show Answer ▼

Filed under: PHP Gotchas No Comments
11Nov/052

Concatenate

What, if anything, is the minimum change (fewest inserted/deleted/modified characters) required to make the output The result is bar:


<?php
class A {
  private $foo = "bar";
  public function __toString() {
    return $this->foo;
  }
}

$myObject = new A();
echo "The result is " . $myObject;
?>

Show Answer ▼

Filed under: PHP Gotchas 2 Comments