Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Clone A Constant

Cloning a constant was useless: this is the version where global constants could be initialized with an object.

The syntax has always been valid, but, at execution time, it would emit an error, as the constant could not be cloned.

PHP code

<?php

class C {}

const A = new C;

var_dump(clone A);

?>

Before

PHP Fatal error:  Constant expression contains invalid operations

Fatal error: Constant expression contains invalid operations

After

object(C)#2 (0) {
}

PHP version change

This behavior changed in 8.1.

Error Messages

Extension

Analyzer

© 2023-2026, Damien Seguy - Exakat