Slide 1

Slide 1 text

php-src is waiting for your contribution or: How to Level Up Your PHP Skills with php-src

Slide 2

Slide 2 text

Self Introduction‒a little old 2025-06-08 #phpxtky php-src is waiting for your contribution 1 • Kentaro Takeda / @KentarouTakeda • 20 years of PHP experience • 2 years of C experience - but that was 30 years ago Honestly, I can't write C anymore • php-src contributor Again, I can't write C!

Slide 3

Slide 3 text

php-src is waiting for your contribution This is important, so I'm repeating it here.

Slide 4

Slide 4 text

4 Ways to Contribute to PHP Development 2025-06-08 #phpxtky php-src is waiting for your contribution 3 1. Running test suites in RC and release distributions of PHP 2. Help finding and diagnosing failed tests, see the phpt documentation 3. Filing and resolving bug reports on GitHub Issues. 4. Help maintain and or translate documentation files at the doc-* repositories on github. Check out our guide for contributors. https://www.php.net/get-involved

Slide 5

Slide 5 text

IMO, for PHP users, the effective way to get involved is through improving tests.

Slide 6

Slide 6 text

How to Write PHP Tests •Tests are written in *.phpt files. •One file corresponds to one test case. --TEST-- Test Fizz Buzz Function --FILE--

Slide 7

Slide 7 text

How to Write PHP Tests The TEST Section •Name of the test case •Used in the test runner’s output --TEST-- Test Fizz Buzz Function --FILE--

Slide 8

Slide 8 text

How to Write PHP Tests The FILE Section •You can write any PHP code •The test runner executes it --TEST-- Test Fizz Buzz Function --FILE--

Slide 9

Slide 9 text

How to Write PHP Tests The EXPECT Section •Expected output •If the actual output is different, the test fails --TEST-- Test Fizz Buzz Function --FILE--

Slide 10

Slide 10 text

My Recommended Way to Contribute to php-src 2025-06-08 #phpxtky php-src is waiting for your contribution 9 • Run tests on the development version of PHP. • If you find a failing test, investigate and fix it. • Even if tests don't fail, improve the coverage, design, or implementation of tests.

Slide 11

Slide 11 text

The Current State of php-src Tests 2025-06-08 #phpxtky php-src is waiting for your contribution 10 • Tests from over a decade ago sit side by side with recent ones. • All of them require maintaining an "all pass" status.

Slide 12

Slide 12 text

Barriers for PHP Developers 2025-06-08 #phpxtky php-src is waiting for your contribution 11 • Tests with quality standards different from today • Insufficient coverage • Excessive use of the error control operator @ • PHP code written in the style of more than a decade ago • Redundant code • Tests with different execution conditions compared to now • Tests dependent on CI settings • Tests that only run in specific environments • False negative tests

Slide 13

Slide 13 text

or: How to Level Up Your PHP Skills with php-src Improving Test Code

Slide 14

Slide 14 text

PHP Test Code in phpt A simple structure based on one file, one test suite. • Due to the nature of the tests, implementations avoiding advanced features are required. • Even when sharing code, using `require()` is the limit. Requires pure PHP skills that do not depend on any specific framework.

Slide 15

Slide 15 text

PHP Test Code in phpt Validate output (standard output) against input (PHP code, function input) • A format often seen in competitive programming and programming learning sites. • The most basic form, both as a test and as a program. Requires pure implementation skills that do not depend on any specific language.

Slide 16

Slide 16 text

How to Find the Code You Need 2025-06-08 #phpxtky php-src is waiting for your contribution 15 • Identify the extension name from the PHP manual (mainly Introduction or Installing/Configuring).

Slide 17

Slide 17 text

Test Storage Directories 2025-06-08 #phpxtky php-src is waiting for your contribution 16 •Tests for PDO ext/pdo/tests •Tests for any extension: ext/EXTENSION/tests

Slide 18

Slide 18 text

Test File Names 2025-06-08 #phpxtky php-src is waiting for your contribution 17 [FEATURE].phpt • Corresponds to a specific feature gh[NUMBER].phpt • Corresponds to GitHub Issue number • The issue will tell you what the test is about bug_[NUMBER].phpt • Corresponds to tickets in the PHP Bug Tracking System • (It is no longer in use.)

Slide 19

Slide 19 text

Ex: A Real gh[NUMBER].phpt Test Case 2025-06-08 #phpxtky php-src is waiting for your contribution 18 __FILE__ // SNIP echo "dsn with correct password / correct user / incorrect password".PHP_EOL; try { $db = new PDO("{$dsn} password={$password}", $user, 'fuga', [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ]); echo "Connected.".PHP_EOL.PHP_EOL; } catch (PDOException $e) { echo $e->getMessage().PHP_EOL; } echo "dsn with correct credentials / incorrect user / incorrect password".PHP_EOL; try { $db = new PDO("{$dsn} user={$user} password={$password}", 'hoge', 'fuga', [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION ]); echo "Connected.".PHP_EOL; } catch (PDOException $e) { echo $e->getMessage().PHP_EOL; } --EXPECT-- dsn without credentials / correct user / correct password Connected. dsn with credentials / no user / no password Connected. dsn with correct user / incorrect user / correct password Connected. dsn with correct password / correct user / incorrect password Connected. dsn with correct credentials / incorrect user / incorrect password Connected. ext/pdo_pgsql/tests/gh12423.phpt

Slide 20

Slide 20 text

Ex: A Real gh[NUMBER].phpt Test Case 2025-06-08 #phpxtky php-src is waiting for your contribution 19 The test case of gh12423.phpt About 10 years ago

Slide 21

Slide 21 text

How to Discover Features You Can Contribute To 2025-06-08 #phpxtky php-src is waiting for your contribution 20 1. Pick a feature you like. 2. Spend about an hour reading its tests. • If it's a test for an Issue or Bug, read the original ticket too. 3. You'll quickly find something you want to fix. • Or, you'll discover a way of using PHP you didn't know about. • Or, you'll find various "reasons" from Issue or pull request information.

Slide 22

Slide 22 text

How to Set Up a Build Environment 2025-06-08 #phpxtky php-src is waiting for your contribution 21 KentarouTakeda/docker-php-src • My personal build environment. • Following the README will set up a complete environment, including external databases. How to Run Tests • ./run-tests.php [phpt file or directory]

Slide 23

Slide 23 text

How to Learn the Basics 2025-06-08 #phpxtky php-src is waiting for your contribution 22 • Building PHP — PHP Internals Book • Official resource on building PHP • Somewhat outdated content (translate version to latest) • Running the test suite — PHP Internals Book • Official resource on running PHP tests

Slide 24

Slide 24 text

Self Introduction‒latest 2025-06-08 #phpxtky php-src is waiting for your contribution 23 • 2 years of C experience - but that was 30 years ago Honestly, I can't write C anymore After contributing to testing and CI for a while, • php-src contributor Again, I can't write C! I have reached a point where I can contribute by adding features in C!

Slide 25

Slide 25 text

Thank you. Let's get started!