Digital Craftsman
  • Search
Sign in Subscribe

reflection

A collection of 2 posts
best-practices

Use reflection in PHP to get a list of constants

PHP lacks a good way of creating enumerations. The best practice is to create constants and use those as possible values. The downside is that you normaly write them hard coded multiple times. For example you've got the following status options: class Person { const STATUS_PENDING = "pending&
19 Jan 2015 1 min read
php

Testing private and protected methods with PHPUnit

It's easy to test public methods with PHPUnit. But what if you want to test protected or private methods? To test those you can use reflection to create a reflection method and invoke this method like the following: $method = new ReflectionMethod('FancyThing', 'doSomethingFancy'); $method-&
15 Jan 2015
Page 1 of 1
Digital Craftsman © 2025
  • Datenschutz
  • Impressum
Powered by Ghost