Skip to content

Instantly share code, notes, and snippets.

@predakanga
Created October 18, 2019 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save predakanga/484a8df36d0878a72b3843ee2a7bbe36 to your computer and use it in GitHub Desktop.
Save predakanga/484a8df36d0878a72b3843ee2a7bbe36 to your computer and use it in GitHub Desktop.
<?php
class Foo {
public function __construct() {
$this->prop = 'a';
$this->{'contains-minus'} = 'b';
$this->{''} = 'c';
}
}
$obj = new Foo();
var_dump($obj->prop); // 'a'
var_dump($obj->contains-minus); // int(0) - notice: undefined property Foo::$contains, warning: undefined constant minus, assumed 'minus'
var_dump($obj->{'contains-minus'}); // 'b'
// var_dump($obj->); // Syntax error, unexpected ')'
// var_dump($obj->''); // Syntax error, unexpected ''''
var_dump($obj->{''}); // 'c'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment