Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

marsuch's avatar

multiple tags for php

Hi, I got to modify the code after another programmer. When I forget what the whole project looks like. So I fight multiple php tags in code. Since the author of the original code inserted html into php.

e.g.:

if ($odp != '') { ?>
                            <tr>
                                <td><span><? if (!empty($_SESSION['wlan'])) echo $row['odp_a']; else  echo $odp; ?></span>
...

Coz causes various errors. Eg: Unclosed '{' on line 578 in E: \ Programs \ Taox \ app \ Legacy \ _include \ function.php on line 1928 - when trying to start the migration.

My question is how best to deal with it. It will be enough to modify the conditions into the template version, therefore.

<?php if ($odp != '') : ?>
<tr>
                                <td><span><? if (!empty($_SESSION['wlan'])) echo $row['odp_a']; else  echo $odp; ?></span>
...
<?php endif ?>

Or you can handle it differently

I don't want to rewrite it, because similar things are in other files. And you have about 4k lines together

0 likes
7 replies
Snapey's avatar

@jlrdw they also mention 'migrations' perhaps you would like to google that and throw a link in here for database migrations also. Or perhaps read the question?

Snapey's avatar

unfortunately you have no choice but to gradually clean up the code. There is no magic wand to untangle this. See if you can start to extract that in-line stuff into views.

You will have a big job though, and ultimately all those 4k lines will have to be re-written - or just note all the behaviour and start from scratch if its as bad as it sounds

I would start by changing all short tags <? for <?php as the short tags are considered deprecated and not enabled on some hosts. This is probably also a sign that this code is on a much earlier, unsupported php version

marsuch's avatar

Well, in my opinion, the author of the original code was just trying to save work. I also saw the original version which did not go under the laravel, but under legacy php + twig. Where was any attempt to switch to mwc. which resulted in a great deal of confusion and a very difficult directory structure of the code, which did not correspond to mwc at all.

As a result, this current project has a legacy folder in the controller folder that contains this problem file. And practically from the first moment I suspect that the original author just copied the code and easily modified it to make the web as a whole work. There are no namespaces. It all looks like a helper, but with the fact that in a given file there is probably everything, logic, part of the view and input processing.

The worst part is that it is a business application, and the project was hand over to me just to add xml export functions for price comparisons and shopping galleries.

jlrdw's avatar

@marsuch php is also a template language, php inside html is normal, in fact blade converts to just that at run time. Even though blade is great its usage is optional.

A good ide will help identify code to fix.

But not saying all of the old code is correct.

And sorry I admit I didn't read that last line concerning PHP tags I thought you meant the other type of tags.

My mind jumped to that video because I watched it a couple weeks ago. I will inform @jeffreyway I made a mistake on this question...

Please or to participate in this conversation.