Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

false, null and true must be recognized as constants in PHP #1693

Closed
ghost opened this issue Jan 5, 2019 · 0 comments
Closed

false, null and true must be recognized as constants in PHP #1693

ghost opened this issue Jan 5, 2019 · 0 comments

Comments

@ghost
Copy link

ghost commented Jan 5, 2019

null is not a keyword

null is a case­‑insensitive predefined constant (see https://secure.php.net/manual/en/reserved.constants.php).

<?php
echo (defined('NULL') && defined('null')) ? 'Defined' : 'Not defined';
// Prints “Defined”

As can be seen in the table below, misplaced null causes a compile error, whereas keywords (or language constructs) cause parse errors.

Naming with any keyword with null
class E_PARSE E_COMPILE_ERROR
constant E_PARSE ⁠* E_NOTICE
function E_PARSE ✔️
method ✔️ ✔️
namespace E_PARSE ✔️
trait E_PARSE E_COMPILE_ERROR
variable ✔️ ✔️

* ⁠Fails on the direct access, i. e., without constant().

So I think Prism should categorize null as a constant, not as a keyword. This is unlikely to adversely affect backward compatibility, because constant is also a well­‑known class, which is already supported by most of the themes.

false and true are also constants

false and true are also case­‑insensitive predefined constants and have all the same features that null has. Thus, they should get the same additional classes.

Solution

Remove null from the keyword regex. Add the following code:

Prism.languages.insertBefore('php', 'class-name', {
	'null': {
		pattern: /\b(?:null)\b/i,
		alias: 'constant predefined-constant'
	}
});

Redefine the boolean regex, which is inherited from clike:

Prism.languages.insertBefore('php', 'class-name', {
	'boolean': {
		pattern: /\b(?:true|false)\b/i,
		alias: 'constant predefined-constant'
	}
});

Expected results

false and true

Result CSS classes
Current token boolean
Expected token boolean constant predefined-constant

null

Result CSS classes
Current token keyword
Expected token null constant predefined-constant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant