Skip to content

fix: issue with GetHeader called with non-existing header#1019

Merged
JohnVillalovos merged 1 commit intodevelopfrom
jlvillal/get_header
Feb 15, 2026
Merged

fix: issue with GetHeader called with non-existing header#1019
JohnVillalovos merged 1 commit intodevelopfrom
jlvillal/get_header

Conversation

@JohnVillalovos
Copy link
Collaborator

This would cause errors like:
PHP Warning: Undefined array key "HTTP_ACCEPT_LANGUAGE" in
/home/runner/work/librebooking/librebooking/lib/Server/Server.php on
line 272

PHP Deprecated: strlen(): Passing null to parameter #1 ($string) of
type string is deprecated in
/home/runner/work/librebooking/librebooking/lib/Server/Server.php on
line 260

This would cause errors like:
 PHP Warning:  Undefined array key "HTTP_ACCEPT_LANGUAGE" in
 /home/runner/work/librebooking/librebooking/lib/Server/Server.php on
 line 272

 PHP Deprecated:  strlen(): Passing null to parameter #1 ($string) of
 type string is deprecated in
 /home/runner/work/librebooking/librebooking/lib/Server/Server.php on
 line 260
Copilot AI review requested due to automatic review settings February 15, 2026 19:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes PHP warnings that occur when GetHeader is called with a non-existing header key. The warnings include an "Undefined array key" error and a deprecated null parameter warning for strlen(). The fix adds a null coalescing operator to return an empty string when the header doesn't exist.

Changes:

  • Modified GetHeader method in lib/Server/Server.php to return an empty string instead of undefined when a header key doesn't exist in $_SERVER

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

public function GetHeader($headerCode)
{
return $_SERVER[$headerCode];
return $_SERVER[$headerCode] ?? '';
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

This change returns an empty string for missing headers, which is inconsistent with other similar methods in the Server class. Methods like GetCookie, GetQuerystring, GetRawForm, and GetSession all return null for missing values.

Additionally, this is inconsistent with the IRestServer interface (lib/WebService/IRestServer.php:43), which defines GetHeader as returning string|null. While Server.php doesn't implement IRestServer, the inconsistency could cause confusion.

Consider using return $_SERVER[$headerCode] ?? null; instead to maintain consistency with the codebase pattern and match the interface definition.

Note: The docblock on line 268 also claims "@return string" but should be "@return string|null" to reflect the actual behavior.

Copilot uses AI. Check for mistakes.
@JohnVillalovos JohnVillalovos merged commit 0f387cc into develop Feb 15, 2026
17 checks passed
@JohnVillalovos JohnVillalovos deleted the jlvillal/get_header branch February 15, 2026 19:31
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.

1 participant

Comments