How to declare a constant of a class of PHP with concatenation?

In the PHP5 class, I want to declare a constant as follows:

class MyClass { const sEOLChars = chr(13) . chr(10); 

which causes the error ( Parse error: syntax error, unexpected '(', expecting ',' or ';' ). How to do this correctly?

+4
source share
2 answers

I decided that I would send the solution as an answer - just in case, if a duplicate of the question is not found.

For your specific error, the problem is calling the chr function. Although there is currently no concatenation to answer the header in the const class.

To solve your problem, you can use the back link \r\n to make your line look like this:

 const sEOLChars = "\r\n"; 

OR you can use the built-in constant PHP_EOL , but keep in mind that it gives you only the end of the line for the current Platform. ^^

+2
source

chr(13) equivalent to "\r" (CARRIAGE RETURN) and chr(10) equivalent to "\n" (LINE FEED). Thus, you can write your code as follows:

 class MyClass { const sEOLChars = "\r\n"; } 
+3
source

All Articles