Skip to content

List of PHP Kata to Update

interrupt-routine edited this page Oct 24, 2025 · 121 revisions

PHP 8.0 with PHPUnit 9.5.2 was added. The kata on this page needs to be updated manually. Any help is appreciated!

Summary of Changes

  • Files are no longer concatenated, but it should work very similarly as before because solution and preloaded files are autoloaded.

    • The preloaded section, the solution and the tests are split in 3 files, respectively: /workspace/default/_preloaded.php, /workspace/default/_solution.php and /workspace/default/tests/{PHPUnit Test Class Name}.php.
    • ⚠️ Breaking change: Global variables from the Solution are no longer accessible out of the box. This has several consequences:
      • Solutions that use global variables no longer work (the global variables will be evaluated to null).

      • While most kata ask the user to write a function or a class, some ask the user to define a global variable (for example Binary Multiple of 3 which asks for a regexp). A global declaration is no longer sufficient to pull the Solution file's global variables into the Test file's scope. A possible fix is to add require '_solution.php'; at the top level of the test suite as well (require_once will not work). However, this will cause the Solution file to be evaluated twice (once by the auto-loading and once by require): for example if the Solution contains the line echo "foo"; at the top-level, foo will be printed twice to the console. Despite this caveat, require still allows to upgrade those kata that only ask for one or several variables. But this will not work when the kata requires both global variables and functions / classes from the user, as the second evaluation caused by the require statement will trigger a duplicate declaration error, e.g.:

        Fatal error: Cannot redeclare foo() (previously declared in /workspace/default/_solution.php:3) in /workspace/default/_solution.php on line 1
        
      Some kata seem impossible to upgrade due to this new runner behavior, see the list below. If you know a way to solve this problem, please get in touch !
  • The name of the test class is now required to end with Test

    • ⚠️ Breaking change: The test class must always be the first class within the test suite's file. If there are other classes besides the test class (for example a class for the reference solution, or for a random tests generator), they must be defined after the test class.
  • Solution and Preloaded file should have <?php

    • Runner prepends this if missing for backwards compatibility, but any new code should include it
  • Test file should have <?php use PHPUnit\Framework\TestCase;

    • Runner prepends this if <?php is missing for backwards compatibility, but any new code should include it
  • ⚠️ Breaking change: From PHP 8.0 on, attempting to access an array key which has not been defined or an out-of-bounds string index will raise an E_WARNING instead of a mere E_NOTICE. The runner treats E_WARNINGS as errors, and aborts the program when one is emitted. As a consequence many solutions containing such accesses no longer pass the tests.

  • PHPUnit is updated to 9.5.2 so there are some breaking changes

    • Testing for exceptions:

      PHPUnit 6 removed support for testing for exceptions with PHPDoc annotations:

     /**
       * @expectedException InvalidArgumentException
       * @expectedExceptionMessage The argument was invalid!
     */
     public function testForException()
     {
         functionThatShouldThrow();
     }

    new code should use expectException():

    public function testForException()
    {
        $this->expectException(InvalidArgumentException::class);
        $this->expectExceptionMessage("The argument was invalid!");
        functionThatShouldThrow();
    }

List of Kata

  1. 'Magic' recursion call depth number
  2. Burrows-Wheeler-Transformation
  3. Check and Mate?
  4. Creating a custom PHP stream wrapper
  5. Divide numbers as strings
  6. Don't rely on luck. - Potentially impossible to upgrade since the solution and tests are no longer concatenated: calling srand() in the solution has no effect on the tests
  7. Evaluate mathematical expression
  8. Fibo akin
  9. Fluent Calculator
  10. How many dots are covered
  11. Implement the (Unnormalized) Cardinal Sine
  12. Largest Palindromic Product
  13. Mirrored Exponential Chunks
  14. Mystery Class
  15. Object-Oriented PHP #1 - Classes, Public Properties and Methods - Potentially impossible to upgrade as it requires the user to write both a class and 3 global variables, see above
  16. PHP in Action #5 - PHPMailer Intro
  17. Reflection in PHP #3 - Using Reflection on Classes
  18. Reflection in PHP #4 - Puzzle Challenge [Assessment]
  19. RoboScript #4 - RS3 Patterns to the Rescue
  20. Text align justify
  21. The Walker
  22. We are Family

After changing assertEquals with assertSame to avoid this problem some katas failed the automatic change and require manual editing:

  1. Binary Genetic Algorithms
  2. Calculate mean and concatenate string
  3. Creating a custom PHP stream wrapper
  4. Disease Spread
  5. Easy Cyclist's Training
  6. Euclidean distance in n dimensions
  7. Fibonacci, Tribonacci and friends
  8. Find the Middle of the Product
  9. Find the area of the rectangle!
  10. FizzBuzz++
  11. Fun with lists: filter
  12. Fun with lists: map
  13. How good are you really?
  14. How many dots are covered
  15. Molecule to atoms
  16. Ordered Count of Characters
  17. Parse a linked list from a string
  18. Pascal's Triangle
  19. Program a Calculator #2 - 3D Vectors
  20. Return the first M multiples of N
  21. Simple Fun #74: Growing Plant
  22. Simple Fun #87: Shuffled Array
  23. Sum and Length
  24. Sum of Array Averages
  25. Sum of Intervals
  26. The Walker
  27. Tiny Three-Pass Compiler
  28. Tortoise racing
  29. We are Family
Clone this wiki locally