Is it better to use consts instead of define()s for readability purposes?

Using consts instead of define()s is generally considered better for readability purposes in PHP. Constants defined with const keyword are part of the class/interface scope, making it easier to understand where they are being used and providing better encapsulation. Additionally, const declarations are checked at compile time, whereas define()s are evaluated at runtime, potentially leading to errors if a constant is redefined.

<?php

class Example {
    const MAX_SIZE = 100;
    
    public function checkSize($value) {
        if ($value > self::MAX_SIZE) {
            echo "Value exceeds maximum size.";
        } else {
            echo "Value is within limits.";
        }
    }
}

$example = new Example();
$example->checkSize(150);

?>