DonJoe
DonJoe

Reputation: 1763

Syntax error when using string concatenation in function argument

Using php 5.5.38.

Simple script:

<?php

function a ($a = 'XXX' . 'TTT') {
    echo 'Hello ' . $a;
}


a();

This fails with:

PHP Parse error: syntax error, unexpected '.', expecting ')' in line 3

Does php 5.5 not support concatenation in there?

Upvotes: 0

Views: 679

Answers (3)

Moubarak Hayal
Moubarak Hayal

Reputation: 199

no php 5.5.38. does not support this method. You need a php version that is >= 5.6.0

Good luck

Upvotes: 0

Lukas Gottschall
Lukas Gottschall

Reputation: 1

It seams like in PHP 7 you can use string concatenation in the function argument defaults, but it doesn't make any sence.

Upvotes: 0

Phiter
Phiter

Reputation: 14982

This feature was added in PHP 5.6. The same rule applies to class propety declarations.

It is now possible to provide a scalar expression involving numeric and string literals and/or constants in contexts where PHP previously expected a static value, such as constant and property declarations and default function arguments.

See: Constant expressions

Upvotes: 2

Related Questions