Skip to content

Instantly share code, notes, and snippets.

@Hais
Last active August 29, 2015 14:16
Show Gist options
  • Save Hais/af622cbca84ba2c51e13 to your computer and use it in GitHub Desktop.
Save Hais/af622cbca84ba2c51e13 to your computer and use it in GitHub Desktop.
php-trait-issue
<?php
trait Bar {
public function jsonSerialize() {
return ["switch" => static::$SWITCH];
}
}
class Foo implements JsonSerializable {
public static $SWITCH = false;
use Bar;
}
$f = new Foo();
Foo::$SWITCH = true;
echo json_encode($f);
// prints {"switch":true}
<?php
trait Bar {
public static $SWITCH = false;
public function jsonSerialize() {
return ["switch" => self::$SWITCH];
}
}
class Foo implements JsonSerializable {
use Bar;
}
$f = new Foo();
Bar::$SWITCH = true;
echo json_encode($f);
// prints {"switch":false}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment