0

I am new in PHP and setup Apache on my Mac 10.11.5. It was working fine for several days, and now -> in PHP cannot be correct handled.

In index.php, I have:

include UC_ROOT."control/admin/backup.php";

In backup.php, I have:

include("data/mydb.php");

In mydb.php, I have:

if(!$this->linkid)    @$this->linkid

When Apache renders the PHP page, it displays:

linkid) @$this->linkid = mys

It seems -> is not recognized correctly.

Could someone please help me? Thank you.

Dylan Wheeler
  • 6,928
  • 14
  • 56
  • 80
X.Hu
  • 73
  • 5
  • 1
    Its not the operator you're having problems with. Apache isnt having PHP process anything so your browser is trying to parse PHP as though its HTML. Make sure that Apache/PHP is configured correctly. – castis Jul 06 '16 at 19:36
  • $this only works inside a class... – Farkie Jul 06 '16 at 19:36
  • @Farkie yes, it is in a class. – X.Hu Jul 06 '16 at 19:40
  • @castis , could you please elaborate it? I have another page: – X.Hu Jul 06 '16 at 19:41
  • hmm, is it possible that you're leaving php at some point before the line you're having issues with? – castis Jul 06 '16 at 19:42
  • @X.Hu can you please post more source code surrounding the issue? This sounds more like a typo error than a server configuration error. Also, what version of PHP did you install? – btomw Jul 06 '16 at 19:50

1 Answers1

0

For Apache to parse the PHP code correctly, even inside included files, you still need to include the <?php opening tag. Otherwise, Apache will send the PHP code completely unparsed.

It looks like that's the most likely issue, but if it is not please post more source code. This does not sound like an Apache configuration issue.

btomw
  • 2,512
  • 2
  • 20
  • 25
  • Hello btomx, thank you so much! It seems this is the problem. I took the code from someone else, but did not tested it throughly. Is it possible to make Apache to be not so strict on this tag? Thank you again. – X.Hu Jul 06 '16 at 20:17
  • @X.Hu, not really... It's a minor inconvenience, though. It's something you'll have to look out for in the future when borrowing/testing code from the internet. The best you can do is setting `short_open_tag=On` in your php.ini file, but all that does is allow you to use `` instead of ` – btomw Jul 06 '16 at 20:24
  • This is a horrible thing.. but you could auto_prepend_file and add a – Farkie Jul 06 '16 at 20:55
  • I feel dirty for mentioning that – Farkie Jul 06 '16 at 20:58
  • 1
    @Farkie That won't work. `auto_prepend_file` works like an include; the PHP tag state isn't preserved over includes. –  Jul 07 '16 at 01:21