I must concatenate the content of 2 variables of a php class in the following way:
<?php
class BD {
//conexion con base de datos
public $cadena0 = 'mysql:host=127.0.0.1;dbname=';
public $cadena1 = 'idCliente00XX';
//public $cadena = "mysql:host=127.0.0.1;dbname=idCliente00XX";
public $cadena = $cadena0.$cadena1;
//etc...
}
?>
I have also tried this way and it gives me the same error
public $cadena1 = 'idCliente00XX';
public $cadena = "mysql:host=127.0.0.1;dbname=".$cadena1;
But it throws me the error
Fatal error: Constant expression contains invalid operations in
I don't know if it's a syntax error, or something that can't be done outright.
You should make that concatenation in the constructor of the class, you define it in the following way: