Skip to content

Update HighlightjsIntegration.class.php - #18

Open
D-Groenewegen wants to merge 2 commits into
Nicolas01:masterfrom
D-Groenewegen:patch-1
Open

Update HighlightjsIntegration.class.php#18
D-Groenewegen wants to merge 2 commits into
Nicolas01:masterfrom
D-Groenewegen:patch-1

Conversation

@D-Groenewegen

Copy link
Copy Markdown

Guard against 'lang' not being set.

Guard against lang not being set
@Nicolas01

Copy link
Copy Markdown
Owner

With the actual code, it seems if the 'lang' variable is not set then PHP will throw a Notice: Undefined variable and the condition will evaluate to false because null is considered falsy.
Could then you explain me the improvements of your PR?

@D-Groenewegen

Copy link
Copy Markdown
Author

Hi Nicolas, it will not evaluate to truthy, that's fine, but because the variable is not set, the server logs will be riddled with PHP warnings (Backend log: PHP Warning: Undefined variable $lang).

Comment thread HighlightjsIntegration.class.php Outdated
}

if ($lang)
if ( isset( $lang ) && $lang !== '' )

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about
if (!empty($lang))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Submitted as suggested. That's better if you need to cater for those cases where $lang may turn out to be false. I removed $lang !== '', which is probably not needed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants