diff --git a/duchain/builders/declarationbuilder.cpp b/duchain/builders/declarationbuilder.cpp --- a/duchain/builders/declarationbuilder.cpp +++ b/duchain/builders/declarationbuilder.cpp @@ -649,27 +649,6 @@ } DeclarationBuilderBase::visitConstantDeclaration(node); closeDeclaration(); - if ( m_reportErrors ) { - // const class members may only be ints, floats, bools or strings - bool badType = true; - if ( IntegralType* type = fastCast(lastType().data()) ) { - switch( type->dataType() ) { - case IntegralType::TypeBoolean: - case IntegralType::TypeFloat: - case IntegralType::TypeInt: - case IntegralType::TypeString: - case IntegralType::TypeNull: - badType = false; - break; - default: - // every other type is a badType (see above) - break; - } - } - if ( badType ) { - reportError(i18n("Only booleans, ints, floats and strings are allowed for class constants."), node->scalar); - } - } } void DeclarationBuilder::visitTraitAliasStatement(TraitAliasStatementAst *node) diff --git a/duchain/tests/duchain.cpp b/duchain/tests/duchain.cpp --- a/duchain/tests/duchain.cpp +++ b/duchain/tests/duchain.cpp @@ -1223,8 +1223,8 @@ QTest::newRow("selfConst") << "const C2 = 1; const C = self::C2;" << 0; QTest::newRow("parentConst") << "const C = parent::P;" << 0; QTest::newRow("null") << "const C = null;" << 0; - - QTest::newRow("array") << "const C = array();" << 1; + QTest::newRow("array") << "const C = array();" << 0; + QTest::newRow("expression") << "const C = 'foo' . 'foo';" << 0; } void TestDUChain::classConst() @@ -1255,8 +1255,8 @@ QTest::newRow("string") << "const C = 'asdf';" << 0 << (uint) IntegralType::TypeString; QTest::newRow("float") << "const C = 0.5;" << 0 << (uint) IntegralType::TypeFloat; QTest::newRow("bool") << "const C = true;" << 0 << (uint) IntegralType::TypeBoolean; - - QTest::newRow("array") << "const C = array();" << 1 << (uint) IntegralType::TypeArray; + QTest::newRow("array") << "const C = array();" << 0 << (uint) IntegralType::TypeArray; + QTest::newRow("expression") << "const C = 'foo' . 'foo';" << 0 << (uint) IntegralType::TypeString; } void TestDUChain::fileConst() diff --git a/parser/php.g b/parser/php.g --- a/parser/php.g +++ b/parser/php.g @@ -725,7 +725,7 @@ identifier=namespacedIdentifier (AS aliasIdentifier=identifier | 0) -> useNamespace ;; - identifier=identifier ASSIGN scalar=staticScalar + identifier=identifier ASSIGN scalar=expr -> constantDeclaration ;; SEMICOLON | CLOSE_TAG @@ -889,7 +889,7 @@ -> parameterList ;; (parameterType=parameterType | 0) (isRef=BIT_AND | 0) - (isVariadic=ELLIPSIS | 0) variable=variableIdentifier (ASSIGN defaultValue=staticScalar | 0) + (isVariadic=ELLIPSIS | 0) variable=variableIdentifier (ASSIGN defaultValue=expr | 0) -> parameter ;; (isNullable=QUESTION | 0) (