0

I have a problem on a WordPress theme I am developing and I need your help. I get a weird PHP error when I am try to move my functions in separated files. So when I change this:

//file: functions.php
function function1(){
...
}
require_once('functions/other_functions.php');

to this:

//file: functions.php
require_once('functions/the_functions.php');
require_once('functions/other_functions.php');

//file: functions/the_functions.php
<?php
    function function1(){
    ...
    }
?>

I get an error says:

parse error: syntax error, unexpected T_STRING in functions/the_functions.php on line 1

this error stop only whith an empty file or this

//file: functions/the_functions.php
<?php

?>

The error appears only on a Linux based server with Light server and PHP 5.3.28 and works perfect on: Windows server with Apache PHP 5.4.16, also on a Linux server with Apache and PHP 5.3.10

Kotheof
  • 3
  • 2

1 Answers1

2

function1(){ is invalid.

Perhaps you meant

function someFunctionName(){

}

Function must have a space between the function declaration and the name of the function. Otherwise it is just a rogue string.

Kai Qing
  • 18,793
  • 5
  • 39
  • 57
  • Are you positive the editor you're using isn't inserting some foreign or unrecognized character? Are you typing or copy/pasting it in the file? – Kai Qing Mar 04 '14 at 20:25
  • I tried both. I get a similar error in 3 files that I try to include. In one file when I insert a space character between – Kotheof Mar 05 '14 at 15:43
  • What encoding is the file being saved with? Ideally you'd set your editor to save with utf-8 encoding. Also, do you have access to shell? Can you create the file on the server through shell and edit it directly? – Kai Qing Mar 05 '14 at 16:01
  • Some files were saved in ANSI encoding, I changed the encoding to utf8 without changing anything else and now the error appears almost in every file I updated. Yes I have shell access. – Kotheof Mar 05 '14 at 16:29
  • At least you're seeing something now. If encoding changes replicated the error then perhaps it is a difference in the supplied encoding and the required encoding. check this: http://stackoverflow.com/questions/9351694/setting-php-default-encoding-to-utf-8 - see if following this advise helps at all. I asked about shell so you could create a new file and edit the contents directly in shell to see if the error persists from an environment that may not produce the same character errors a text editor could create. – Kai Qing Mar 05 '14 at 16:35
  • Thanks for all your help but I am not sure that this is the problem. I I tried to restore the encoding as it was before but the errors remain. Is php using any type of caching in the files that are not modified? – Kotheof Mar 05 '14 at 17:02
  • not that I know of. If they work fine on another server then all that's left are environmental settings with lightserver. I don't think I know enough about that to advise – Kai Qing Mar 05 '14 at 17:43
  • Thanks anyway for your time! – Kotheof Mar 05 '14 at 17:59