No Self Referencing Constants

<?php

class x {
    const A = x::A + 1;

    const B = x::C + 1;
    const C = x::B + 1;

}

It is not possible to define a recursive PHP class constant, although it is possible to write it. A self referencing constant may be with itself, or it may use a complex right of class definitions before failing.

There is a dedicated PHP error message for this situation: ‘Cannot declare self-referencing constant’.

One fun aspect is that the is not detected at compilation time, but at execution time, when the constant is actually used. The problem may lie dormant for a long time before revealing itself.

The error is also moved by other reported when several constants are compounded to build one, in a cyclic fashion.

See Also

PHP Error Messages

PHP Features

Last updated: 14 July 2026