Magic constants are filled in by the compiler from where they appear: __LINE__, __FILE__, __DIR__, __FUNCTION__, __CLASS__, __METHOD__, __NAMESPACE__, __TRAIT__ and __PROPERTY__ (PHP 8.4, inside a property hook only). Product::class gives the fully qualified class name. The workhorse is __DIR__: require __DIR__ . '/config.php' works from any directory.
<?php
namespace Shop\Catalog;
final class Product
{
public string $sku = 'bk-7' { get => __PROPERTY__ . '=' . strtoupper($this->sku); }
public function report(): void
{
echo __METHOD__, ' | ', __FUNCTION__, ' | ', self::class, "\n";
echo $this->sku, ' | ', basename(__FILE__), ':', __LINE__, ' | ', __DIR__, "\n";
}
}
(new Product())->report();Output
Shop\Catalog\Product::report | report | Shop\Catalog\Product sku=BK-7 | Product.php:11 | /tmp/ch04-02/shop/src/Catalog
To see what a variable holds, print_r() reads best but prints false and null as nothing, var_dump() shows every type and length, and var_export() prints PHP you can paste into a test. print_r($order, true) returns the text instead, ready for error_log(). var_dump and VarDumper goes further.