0

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?

10
  • 3
    You can't have expressions inside the function default parameters, only primitive values. Commented Oct 30, 2018 at 14:24
  • @Phiter You mean at all or just in php 5.5? Commented Oct 30, 2018 at 14:24
  • I believe just in 5.5. Look secure.php.net/manual/en/… Commented Oct 30, 2018 at 14:25
  • It works on 7.1 ideone.com/zdpGok Commented Oct 30, 2018 at 14:26
  • 1
    It was added in PHP 5.6 - see the section at the top of the changelog labelled Constant Expressions Commented Oct 30, 2018 at 14:27

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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

Good luck

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.