You are here: PSPad forum > Bug report / Hlášení chyb > PHP Syntax highlighting error

PHP Syntax highlighting error

Goto Page: 1 2 Next

#1 PHP Syntax highlighting error

Posted by: viplex | Date: 2015-06-22 12:05 | IP: IP Logged

Hi, I have seen that a closing php tag in comments may lead to errors in php syntax highlighting. This error occurs in html multihighlighter too..

Let's say I have

<p><?= $var ?></p>

If you put a comment aroung that, it should be treated as legit

// <p><?= $var ?></p>

This is not working properly, because the closing tag suggests the end of the file, which is not right.

Error:
image

How it should behave:
image

Edited 1 time(s). Last edit at 2015-06-22 12:05 by viplex.

Options: Reply | Quote | Up ^


#2 Re: PHP Syntax highlighting error

Posted by: pspad | Date: 2015-06-22 13:13 | IP: IP Logged

Switch syntax highlighter to PHP instead of the HTML multihighlighter.

Options: Reply | Quote | Up ^


#3 Re: PHP Syntax highlighting error

Posted by: viplex | Date: 2015-06-22 15:33 | IP: IP Logged

Hello,
this works and fixes the problems in .php files, which is good.
Unfortunately there are use cases where html is included there too like:


<title><?= $var ;></title>

switching to php only will remove highlighting for html elements.
Is there any way to integrate this into the multihighlighter or does this break constraints that are necessary for html syntax highlighting?

Best Regards

Options: Reply | Quote | Up ^


#4 Re: PHP Syntax highlighting error

Posted by: Andreas | Date: 2015-06-22 17:24 | IP: IP Logged

// <p><?= $var ?></p>
But this is no comment. The slashes are not in PHP. It should output two slashes in the browser followed by a paragraph. Highlight with multi HL at this point is ok for me.

Options: Reply | Quote | Up ^


#5 Re: PHP Syntax highlighting error

Posted by: Wirek | Date: 2015-06-27 11:09 | IP: IP Logged

Your assumption is bad, Andreas, because viplex has never claimed that it was a full source code in his post above. It is obvious that it was just a problematic fragment (single line) of his source code.

I agree with viplex that PHP files may also contain other (than PHP per se) source codes like: (X)HTML, JavaScript, CSS... And that is why it would be very, very nice if "multihighlighter" for PHP files worked correctly with 2 character sequence "?>" in the following cases:
1. one-line comments (after // 2 char sequence);
2. multi-line block comments (between /* and */ 2 char sequences);
3. multi-line single quoted strings (between ' and ' pair except \' 2 char possible sequences);
4. multi-line double quoted strings (between " and " pair except \" 2 char possible sequences);
5. multi-line unquoted Nowdoc strings (between <<<'Some_Identifier1' and Some_Identifier1;);
6. multi-line unquoted Heredoc strings (between <<<Some_Identifier2 and Some_Identifier2;).

With the priority of implementation in PSPad from 1 (highest) to 6 (lowest) in my opinion. winking smiley
More info on subject of strings in PHP: php.net

Options: Reply | Quote | Up ^


#6 Re: PHP Syntax highlighting error

Posted by: Wirek | Date: 2015-06-27 11:34 | IP: IP Logged

I understand that it's not a trivial issue because for example single line comments ("//") may occur in:
- PHP code;
- JavaScript code that is inside (X)HTML code that in turn is inside PHP file surrounded with PHP code and with possible PHP insertions in (X)HTML or in JavaScript blocks.

What is more - multiline block comments ("/* ... */") may even occur in CSS blocks that are in (X)HTML code inside PHP files.

But... "multihighlighter" feature is most important exactly in such messy/untidy (PHP) files where human eye is easily tricked and resulting problems in source code are very difficult to find and correct.

Anyway I haven't experienced this issue in Eclipse IDE - heavyweight, I know. winking smiley

Options: Reply | Quote | Up ^


#7 Re: PHP Syntax highlighting error

Posted by: Andreas | Date: 2015-06-27 14:13 | IP: IP Logged

Instead of describing the problems, why not showing a complete and valid (but small) code with all the highlight errors so we can test it by our own with copy and paste?

Options: Reply | Quote | Up ^


#8 Re: PHP Syntax highlighting error

Posted by: viplex | Date: 2015-06-30 16:30 | IP: IP Logged

Hi,
actually I do not understand why you would need another example if I already posted one in the first post and it has been approved as a fault by the pspad creator.

But here it is:


<p>This is a cool text here</p>
<?php
/*
<p>This is a cool <?= $variable ?> here</p>
*/
?>

I admin that this may look odd, but it's just a sample and a use case where you could have that is a view in MVC, were you just want to comment something away (because it's not used yet/anymore).

Here is how pspad renders it:
image

Here is how it should be shown in my opinion (and that of notepad++).
image

If you chose php as syntax highlighter, it's shown correct, because that's valid php.

Edited 1 time(s). Last edit at 2015-06-30 16:31 by viplex.

Options: Reply | Quote | Up ^


#9 Re: PHP Syntax highlighting error

Posted by: Andreas | Date: 2015-06-30 19:15 | IP: IP Logged

As I think you should post a real life example that makes sense. e.g.

<?php

/**
* Please use "<?= $variable ?>" to print your variables
*/

// Please use "<?= $variable ?>" to print your variables

?>

In your example you're trying to prevent output of HTML markup by using a PHP wrapper and missuse the PHP comment to achieve this. This is unusual and bad coding style. But you are right, the highlighting in my example is wrong with multihighlighter.

Options: Reply | Quote | Up ^


#10 Re: PHP Syntax highlighting error

Posted by: viplex | Date: 2015-07-11 09:59 | IP: IP Logged

Hello,
that has nothing to do with bad style because there is no convention regarding comments content.

Because you are not using it does not mean that it's unusual, in bigger projects (such) comments are used on a regular basis and annotations are necessary.

It's a php comment and I can put everything there, therefore it's a comment.
The highlighter does not do his job and therefore it's a valid bug as other users agree.

Edited 2 time(s). Last edit at 2015-07-11 10:04 by viplex.

Options: Reply | Quote | Up ^


Goto Page: 1 2 Next





Editor PSPad - freeware editor, © 2001 - 2024 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR