Skip to content

List of PHP Kata to Update

interrupt-routine edited this page Jul 16, 2025 · 74 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

    • Accessing Global variables in the user's file (_solution.php):

      Since moving away from file concatenation, 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.

      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). Because the files are no longer concatenated, a global declaration is no longer sufficient to pull the user's global variables into the test suite's scope. One solution 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 user's file to be evaluated twice (once by the auto-loading and once by require): for example if the user's file 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 now required to end with Test

  • 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
  • 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. Brainfuck Translator
  3. Buddy Pairs
  4. Burrows-Wheeler-Transformation
  5. Buying a car
  6. Car Park Escape
  7. Catalog
  8. Challenge Fun #14: Target Game
  9. Check and Mate?
  10. Ciphers #1 - The 01 Cipher
  11. Color Choice
  12. Connect 4
  13. Creating a custom PHP stream wrapper
  14. Divide numbers as strings
  15. Domain name validator
  16. 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
  17. Esolang Interpreters #1 - Introduction to Esolangs and My First Interpreter (MiniStringFuck)
  18. Esolang: InfiniTick
  19. Evaluate mathematical expression
  20. Experimenting with a sequence of complex numbers
  21. Factorial decomposition
  22. Family Gift Exchange / Names Out of a Hat
  23. Fibo akin
  24. Financing Plan on Planet XY140Z-n
  25. Fluent Calculator
  26. Functions of Integers on Cartesian Plane
  27. Generate keywords
  28. Get angle between hour and minute hands
  29. Going to the cinema
  30. Going to zero or to infinity?
  31. Good words
  32. Hofstadter Q
  33. How many dots are covered
  34. How Much?
  35. Human readable duration format
  36. Hungry Hippos
  37. Implement the (Unnormalized) Cardinal Sine
  38. Is my friend cheating?
  39. Is there an arrow missing ? (Relations - Part1: Reflexivity)
  40. John and Ann sign up for Codewars
  41. Largest Palindromic Product
  42. League Player Rank
  43. Linked Lists - Get Nth Node
  44. Linked Lists - Insert Nth Node
  45. List of all Rationals
  46. Make sets
  47. Mirrored Exponential Chunks
  48. Mystery Class
  49. 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
  50. One Line Task: Largest Rectangle
  51. Pattern Generator
  52. Pattern Generator (mirrored)
  53. Perimeter of squares in a rectangle
  54. PHP Immutable
  55. PHP in Action #5 - PHPMailer Intro
  56. Pigs in a Pen
  57. Points in the circle
  58. Pokemon Damage Calculator
  59. Positions Average
  60. Product of two squares
  61. Pull your words together, man!
  62. Rectangle into Squares
  63. Reflection in PHP #3 - Using Reflection on Classes
  64. Reflection in PHP #4 - Puzzle Challenge [Assessment]
  65. RoboScript #4 - RS3 Patterns to the Rescue
  66. Roman Numerals Decoder
  67. Screen Locking Patterns
  68. Selective memory
  69. Shortest Distance to a Character
  70. Simple assembler interpreter
  71. Simple consecutive pairs
  72. Simplifying multilinear polynomials
  73. Smallest possible sum
  74. Snakes and Ladders
  75. Square Pi's
  76. String Scramble
  77. Sum Mixed Array
  78. Text align justify
  79. Texting with an old-school mobile phone
  80. The Skiponacci Sequence
  81. The Walker
  82. Wave Sorting
  83. We are Family
  84. Weight for weight

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

  1. A Rule of Divisibility by 7
  2. Area of an arrow
  3. Binary Genetic Algorithms
  4. Brainfuck Translator
  5. Buying a car
  6. Calculate mean and concatenate string
  7. Closest and Smallest
  8. Convert a String to a Number!
  9. Creating a custom PHP stream wrapper
  10. Disease Spread
  11. Driving School Series #2
  12. Easy Cyclist's Training
  13. Easy Line
  14. Euclidean distance in n dimensions
  15. Fibonacci, Tribonacci and friends
  16. Financing Plan on Planet XY140Z-n
  17. Find the Middle of the Product
  18. Find the area of the rectangle!
  19. FizzBuzz++
  20. Fun with lists: filter
  21. Fun with lists: map
  22. Functions of Integers on Cartesian Plane
  23. Heron's formula
  24. How good are you really?
  25. How many dots are covered
  26. League Player Rank
  27. Looking for a benefactor
  28. Molecule to atoms
  29. Mutual Recursion
  30. One Line Task: Largest Rectangle
  31. Ordered Count of Characters
  32. Parse a linked list from a string
  33. Pascal's Triangle
  34. Pattern Generator (mirrored)
  35. Program a Calculator #2 - 3D Vectors
  36. Quarter of the year
  37. Regex Tic Tac Toe Win Checker
  38. Regexp Basics - is it IPv4 address?
  39. Return the closest number multiple of 10
  40. Return the first M multiples of N
  41. Reverse polish notation calculator
  42. Screen Locking Patterns
  43. Send in the Clones
  44. Simple Fun #181: Rounding
  45. Simple Fun #74: Growing Plant
  46. Simple Fun #87: Shuffled Array
  47. Square Pi's
  48. Sum and Length
  49. Sum of Array Averages
  50. Sum of Intervals
  51. Sum of positive
  52. The Walker
  53. Tiny Three-Pass Compiler
  54. Tortoise racing
  55. Wave Sorting
  56. We are Family
  57. simple calculator
Clone this wiki locally