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

Use zero instead of null as empty arg for header() for PHP 8.1+ compat #7452

Merged
merged 3 commits into from
Feb 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions includes/class-amp-http.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static function send_header( $name, $value, $args = [] ) {
$args = array_merge(
[
'replace' => true,
'status_code' => null,
'status_code' => 0,
],
$args
);
Expand All @@ -92,7 +92,7 @@ public static function send_header( $name, $value, $args = [] ) {
header(
sprintf( '%s: %s', $name, $value ),
$args['replace'],
$args['status_code']
empty( $args['status_code'] ) ? 0 : (int) $args['status_code']
);
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/php/src/Instrumentation/ServerTimingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public function test_it_can_send_headers_directly() {
'name' => 'Server-Timing',
'value' => 'event-10;desc="Event N°10";dur="12345.7"',
'replace' => true,
'status_code' => null,
'status_code' => 0,
],
AMP_HTTP::$headers_sent
);
Expand Down Expand Up @@ -275,7 +275,7 @@ public function test_it_can_send_headers_via_action() {
'name' => 'Server-Timing',
'value' => 'event-11;desc="Event N°11";dur="3.1"',
'replace' => true,
'status_code' => null,
'status_code' => 0,
],
AMP_HTTP::$headers_sent
);
Expand Down Expand Up @@ -357,7 +357,7 @@ public function test_it_restricts_output_in_non_verbose_mode() {
'name' => 'Server-Timing',
'value' => 'main-event;desc="Main Event";dur="1.2"',
'replace' => true,
'status_code' => null,
'status_code' => 0,
],
AMP_HTTP::$headers_sent
);
Expand Down Expand Up @@ -385,7 +385,7 @@ public function test_it_doesnt_restrict_output_in_verbose_mode() {
'name' => 'Server-Timing',
'value' => 'main-event;desc="Main Event";dur="1.2",verbose-event;desc="Verbose Event";dur="3.4"',
'replace' => true,
'status_code' => null,
'status_code' => 0,
],
AMP_HTTP::$headers_sent
);
Expand Down
48 changes: 24 additions & 24 deletions tests/php/test-class-amp-http.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function test_send_header_no_args() {
'name' => 'Foo',
'value' => 'Bar',
'replace' => true,
'status_code' => null,
'status_code' => 0,
],
AMP_HTTP::$headers_sent
);
Expand All @@ -71,7 +71,7 @@ public function test_send_header_replace_arg() {
'name' => 'Foo',
'value' => 'Bar',
'replace' => false,
'status_code' => null,
'status_code' => 0,
],
AMP_HTTP::$headers_sent
);
Expand Down Expand Up @@ -116,7 +116,7 @@ public function test_send_server_timing_positive_duration() {
$this->assertEquals( 'desc="Description"', $values[1] );
$this->assertStringStartsWith( 'dur=123000.', $values[2] );
$this->assertFalse( AMP_HTTP::$headers_sent[0]['replace'] );
$this->assertNull( AMP_HTTP::$headers_sent[0]['status_code'] );
$this->assertSame( 0, AMP_HTTP::$headers_sent[0]['status_code'] );
}

/**
Expand All @@ -133,7 +133,7 @@ public function test_send_server_timing_negative_duration() {
$this->assertEquals( 'name', $values[0] );
$this->assertStringStartsWith( 'dur=0.', $values[1] );
$this->assertFalse( AMP_HTTP::$headers_sent[0]['replace'] );
$this->assertNull( AMP_HTTP::$headers_sent[0]['status_code'] );
$this->assertSame( 0, AMP_HTTP::$headers_sent[0]['status_code'] );
}

/**
Expand Down Expand Up @@ -295,19 +295,19 @@ public function test_send_cors_headers() {
'name' => 'Access-Control-Allow-Origin',
'value' => home_url(),
'replace' => false,
'status_code' => null,
'status_code' => 0,
],
[
'name' => 'Access-Control-Allow-Credentials',
'value' => 'true',
'replace' => true,
'status_code' => null,
'status_code' => 0,
],
[
'name' => 'Vary',
'value' => 'Origin',
'replace' => false,
'status_code' => null,
'status_code' => 0,
],
],
AMP_HTTP::$headers_sent
Expand All @@ -326,31 +326,31 @@ public function test_send_cors_headers() {
'name' => 'Access-Control-Allow-Origin',
'value' => 'https://cdn.ampproject.org',
'replace' => false,
'status_code' => null,
'status_code' => 0,
],
[
'name' => 'Access-Control-Allow-Credentials',
'value' => 'true',
'replace' => true,
'status_code' => null,
'status_code' => 0,
],
[
'name' => 'Vary',
'value' => 'Origin',
'replace' => false,
'status_code' => null,
'status_code' => 0,
],
[
'name' => 'AMP-Access-Control-Allow-Source-Origin',
'value' => 'https://cdn.ampproject.org',
'replace' => true,
'status_code' => null,
'status_code' => 0,
],
[
'name' => 'Access-Control-Expose-Headers',
'value' => 'AMP-Access-Control-Allow-Source-Origin',
'replace' => false,
'status_code' => null,
'status_code' => 0,
],
],
AMP_HTTP::$headers_sent
Expand All @@ -369,31 +369,31 @@ public function test_send_cors_headers() {
'name' => 'Access-Control-Allow-Origin',
'value' => 'https://cdn.ampproject.org',
'replace' => false,
'status_code' => null,
'status_code' => 0,
],
[
'name' => 'Access-Control-Allow-Credentials',
'value' => 'true',
'replace' => true,
'status_code' => null,
'status_code' => 0,
],
[
'name' => 'Vary',
'value' => 'Origin',
'replace' => false,
'status_code' => null,
'status_code' => 0,
],
[
'name' => 'AMP-Access-Control-Allow-Source-Origin',
'value' => home_url(),
'replace' => true,
'status_code' => null,
'status_code' => 0,
],
[
'name' => 'Access-Control-Expose-Headers',
'value' => 'AMP-Access-Control-Allow-Source-Origin',
'replace' => false,
'status_code' => null,
'status_code' => 0,
],
],
AMP_HTTP::$headers_sent
Expand Down Expand Up @@ -453,7 +453,7 @@ static function () {
'name' => 'AMP-Redirect-To',
'value' => $url,
'replace' => true,
'status_code' => null,
'status_code' => 0,
],
AMP_HTTP::$headers_sent
);
Expand All @@ -462,7 +462,7 @@ static function () {
'name' => 'Access-Control-Expose-Headers',
'value' => 'AMP-Redirect-To',
'replace' => false,
'status_code' => null,
'status_code' => 0,
],
AMP_HTTP::$headers_sent
);
Expand All @@ -478,7 +478,7 @@ static function () {
'name' => 'AMP-Redirect-To',
'value' => preg_replace( '#^\w+:#', '', $url ),
'replace' => true,
'status_code' => null,
'status_code' => 0,
],
AMP_HTTP::$headers_sent
);
Expand All @@ -487,7 +487,7 @@ static function () {
'name' => 'Access-Control-Expose-Headers',
'value' => 'AMP-Redirect-To',
'replace' => false,
'status_code' => null,
'status_code' => 0,
],
AMP_HTTP::$headers_sent
);
Expand All @@ -502,7 +502,7 @@ static function () {
'name' => 'AMP-Redirect-To',
'value' => set_url_scheme( home_url( '/new-location/' ), 'https' ),
'replace' => true,
'status_code' => null,
'status_code' => 0,
],
AMP_HTTP::$headers_sent
);
Expand All @@ -518,7 +518,7 @@ static function () {
'name' => 'AMP-Redirect-To',
'value' => set_url_scheme( home_url( '/new-location/' ), 'https' ),
'replace' => true,
'status_code' => null,
'status_code' => 0,
],
AMP_HTTP::$headers_sent
);
Expand All @@ -533,7 +533,7 @@ static function () {
'name' => 'AMP-Redirect-To',
'value' => set_url_scheme( home_url(), 'https' ),
'replace' => true,
'status_code' => null,
'status_code' => 0,
],
AMP_HTTP::$headers_sent
);
Expand Down