Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2022-11-21 19:17:21

ironmangary
Member
From: United States
Registered: 2022-10-13
Posts: 36

Baffling PHP Syntax Errors

While I wouldn’t consider myself an “expert” in php, I’ve written thousands of lines of code in my life, so I’m not a novice, either. But the error I’m hitting now has me stumped.

The first two lines of my function are simply:

global $session;
$op = httpget(‘op’);

I have this code exactly like this in dozens of scripts and have never hit an error with it. The error is:

Parse error: syntax error, unexpected ‘op’ (T_STRING), expecting ‘)’ in travel.php on line 88

Obviously, not something I’m doing in txp, but I’m hoping one of you awesome people can give me some pointers. I typically script in Notepad and upload my stuff via WinSCP (SFTP) and I’m starting to wonder if it’s encoding or something stupid like that…because huh?

Thanks!

Offline

#2 2022-11-21 22:20:32

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,402
Website GitHub

Re: Baffling PHP Syntax Errors

Couple of observations:

  1. I’ve never heard of httpgetas a PHP function. Presume it’s in some library you have installed?
  2. I presume the curly quotes were put there by the forum because those would certainly cause it to throw a wobbly.
  3. Where is this code written? In a Page template/Form? Or in an article? If the latter then it’s likely to be Textile getting in the way.

If the PHP is in the article body you can escape it by either:

A) Setting the field processing to Leave text untouched.
B) Surrounding the code with double equals if it’s a block:

==<txp:php>
// Your code here.
</txp:php>==

C) precede the block or code with notextile. (use a double dot after it for multiline code blocks).

Hope some of that helps.

Edit: ugh, I see that your error message says it’s in travel.php, which implies it’s an external script file. In which case, ignore the article stuff I mentioned. How do you invoke the file? Through an include?

Last edited by Bloke (2022-11-21 22:24:04)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#3 2022-11-21 22:34:16

ironmangary
Member
From: United States
Registered: 2022-10-13
Posts: 36

Re: Baffling PHP Syntax Errors

Hey Stef,

Yeah, this is a project seperate from TxP. The travel.php is a module I wrote for a game engine that uses hooks. The httpget() function is part of the engine. Also, yeah, the forum added the fancy single quotes; in my code, it’s plain text.

I’ve been writing modules for this engine for years and have never encountered such an error before. I can’t exactly ask the authors since the engine has been abandoned. It is, however, PHP 7.4 compatible.

Offline

#4 2022-11-21 23:15:51

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,402
Website GitHub

Re: Baffling PHP Syntax Errors

Hmmm, so how does this run? In browser? Command line? Does it spit that error to screen or log file?

And is the server definitely running PHP 7.4 and not something else?

If you’ve been writing code using the engine for years and only now it’s giving problems, it smacks of something environmental.


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2022-11-21 23:38:24

ironmangary
Member
From: United States
Registered: 2022-10-13
Posts: 36

Re: Baffling PHP Syntax Errors

Yes, it runs in a browser and PHP errors display to screen.

I shouldn’t say the entire engine is PHP 7.4 compatible. The database functions were made to be 7.4 compatible. I can’t vouch for the rest of the code.

Offline

#6 2022-11-23 00:51:08

ironmangary
Member
From: United States
Registered: 2022-10-13
Posts: 36

Re: Baffling PHP Syntax Errors

For anyone who was following along, and I know you were waiting for my update…

It’s fixed. I started a new notepad document, rewrote the 90 some lines, and it worked. No clue. I blame Windows.

Offline

Board footer

Powered by FluxBB