php-src icon indicating copy to clipboard operation
php-src copied to clipboard

Enums can't be initialized in the constructor

Open solidpulse opened this issue 4 years ago • 0 comments

Description

I have the following code:

<?php

enum TKind {

  case TK_PUNCT; 
  case TK_NUM;   
  case TK_EOF;   
}

class A{
    
    public TKind $kind;
    public function  __constructor($kindArg){
        $this->kind = $kindArg;
    }
}

$a = new A(Tkind::TK_PUNCT);
var_dump($a);

I am expecting $a->kind to be initialized, yet the output looks like the following,

object(A)#1 (0) {
  ["kind"]=>
  uninitialized(TKind)
}

Demo: https://3v4l.org/18V1r#v8.1.5

PHP Version

8.1.5

Operating System

No response

solidpulse avatar Apr 16 '22 08:04 solidpulse