<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jérémie Fréreault</title>
    <description>The latest articles on DEV Community by Jérémie Fréreault (@jrmie_frreault_9f39816).</description>
    <link>https://dev.to/jrmie_frreault_9f39816</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3024771%2Fe23e2b78-79a4-4e40-9bc1-5f2d1565737c.jpeg</url>
      <title>DEV Community: Jérémie Fréreault</title>
      <link>https://dev.to/jrmie_frreault_9f39816</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/jrmie_frreault_9f39816"/>
    <language>en</language>
    <item>
      <title>Defining PHP Constants That Collapse When Observed</title>
      <dc:creator>Jérémie Fréreault</dc:creator>
      <pubDate>Mon, 14 Apr 2025 02:04:32 +0000</pubDate>
      <link>https://dev.to/jrmie_frreault_9f39816/defining-php-constants-that-collapse-when-observed-4hnf</link>
      <guid>https://dev.to/jrmie_frreault_9f39816/defining-php-constants-that-collapse-when-observed-4hnf</guid>
      <description>&lt;p&gt;&lt;strong&gt;What if your constants didn't exist until you looked at them?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In PHP, a constant is usually… well, constant. Boring. Static. Defined once, and always the same.&lt;br&gt;&lt;br&gt;
But what if we injected a little quantum physics into our code — something that &lt;strong&gt;collapses into a value only when observed&lt;/strong&gt;?&lt;/p&gt;

&lt;p&gt;Meet &lt;code&gt;heisenconstant()&lt;/code&gt;: a playful yet powerful utility inspired by &lt;strong&gt;Heisenberg's uncertainty principle&lt;/strong&gt;, giving you &lt;strong&gt;lazy-evaluated, memoized, type-aware, introspectable constants&lt;/strong&gt; with quantum flavor.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;This feature is now part of the &lt;a href="https://github.com/jeremie5/dataphyre" rel="noopener noreferrer"&gt;&lt;strong&gt;Dataphyre PHP framework&lt;/strong&gt;&lt;/a&gt; — where performance, clarity, and originality converge at the architectural level.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2fmsznnvk1ee750nenet.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2fmsznnvk1ee750nenet.png" alt="Function comment" width="521" height="420"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;h2&gt;
  
  
  The Implementation
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;heisenconstant&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;array&lt;/span&gt; &lt;span class="nv"&gt;$map&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;foreach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$map&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$key&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;Closure&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
            &lt;span class="nv"&gt;$map&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;Closure&lt;/span&gt; &lt;span class="nv"&gt;$fn&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;mixed&lt;/span&gt; &lt;span class="nv"&gt;$cached&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nv"&gt;$evaluated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

                &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Closure&lt;/span&gt; &lt;span class="nv"&gt;$fn&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
                    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$fn&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;

                &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__toString&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;cached&lt;/span&gt; &lt;span class="o"&gt;??=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;()));&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;

                &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;toInt&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;cached&lt;/span&gt; &lt;span class="o"&gt;??=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;()));&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;

                &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;toFloat&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;float&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;float&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;cached&lt;/span&gt; &lt;span class="o"&gt;??=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;()));&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;

                &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;toArray&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;array&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;array&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;cached&lt;/span&gt; &lt;span class="o"&gt;??=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;()));&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;

                &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;toBool&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;cached&lt;/span&gt; &lt;span class="o"&gt;??=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;()));&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;

                &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;raw&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;mixed&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;cached&lt;/span&gt; &lt;span class="o"&gt;??=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;

                &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;reset&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;cached&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;evaluated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;

                &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;mixed&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;evaluated&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
                    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;)();&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;

                &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__debugInfo&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt; &lt;span class="kt"&gt;array&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
                        &lt;span class="s1"&gt;'status'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;evaluated&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="s1"&gt;'evaluated'&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'unevaluated'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                        &lt;span class="s1"&gt;'value'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;cached&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s1"&gt;'[not yet evaluated]'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                    &lt;span class="p"&gt;];&lt;/span&gt;
                &lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="p"&gt;};&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nb"&gt;define&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$map&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How It Works
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. Define with Lazy Closures
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nf"&gt;heisenconstant&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'MY_CONST'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'uuid'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bin2hex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;random_bytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;)),&lt;/span&gt;
    &lt;span class="s1"&gt;'now'&lt;/span&gt;  &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'c'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Instead of precomputing values, we pass closures that won’t run until needed.&lt;/p&gt;


&lt;h3&gt;
  
  
  2. Collapse on Observation
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;echo&lt;/span&gt; &lt;span class="no"&gt;MY_CONST&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'uuid'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt; &lt;span class="c1"&gt;// Evaluates once, then cached&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The first time you observe a value — by casting it to a string — it executes the closure and remembers the result.&lt;/p&gt;


&lt;h3&gt;
  
  
  3. Introspect the Quantum State
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nb"&gt;var_dump&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;MY_CONST&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'now'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Gives output like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;object(class@anonymous)#1 (2) {
  ["status"] =&amp;gt; "evaluated"
  ["value"]  =&amp;gt; "2025-04-10T23:10:00+00:00"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can literally see whether a value has been observed or not.&lt;br&gt;&lt;br&gt;
Just like a cat in a box.&lt;/p&gt;




&lt;h2&gt;
  
  
  Bonus Features
&lt;/h2&gt;

&lt;p&gt;These quantum values aren't just for printing. You can access them using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;toInt()&lt;/code&gt; – return the value cast to integer
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toFloat()&lt;/code&gt; – cast to float
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toArray()&lt;/code&gt; – cast to array
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;toBool()&lt;/code&gt; – cast to boolean
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;raw()&lt;/code&gt; – get the raw, unmodified value
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;reset()&lt;/code&gt; – uncollapse the state and force re-evaluation on next access&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each key in your constant behaves like its own particle, &lt;strong&gt;independently observed&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why This Is Cool
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Performance&lt;/strong&gt;: Don’t compute unless you need it
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clean Debugging&lt;/strong&gt;: &lt;code&gt;__debugInfo()&lt;/code&gt; reveals state — no magic
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Powerfully Weird&lt;/strong&gt;: Constants that obey Schrödinger, not RFCs
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Safe&lt;/strong&gt;: Still defined with &lt;code&gt;define()&lt;/code&gt;, just with quantum flavor
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Composable&lt;/strong&gt;: You can mix closures and static values&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Real-World Use Cases
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ROOTPATH['theme']&lt;/code&gt;: resolve theme path lazily at boot
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;SYSTEM_STATE['uuid']&lt;/code&gt;: guaranteed unique per boot, but only if accessed
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;DEBUG_SNAPSHOTS['config_dump']&lt;/code&gt;: snapshot config lazily for logs
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;BUILD_INFO['git_hash']&lt;/code&gt;: only needed in debug output or crash reports&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Warning: Here Be Dragons
&lt;/h2&gt;

&lt;p&gt;Heisenconstants are safe — until you start counting on them being &lt;strong&gt;unobserved&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you rely on the closure &lt;em&gt;not&lt;/em&gt; being triggered, be careful with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Logging&lt;/li&gt;
&lt;li&gt;Serialization&lt;/li&gt;
&lt;li&gt;Third-party tools&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Any cast to string or type observation &lt;strong&gt;collapses the quantum wave&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you're unsure, use &lt;code&gt;reset()&lt;/code&gt; to re-establish the superposition state.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;heisenconstant()&lt;/code&gt; is a &lt;strong&gt;philosophical and practical coding artifact&lt;/strong&gt; — a reminder that sometimes code should do less until it's asked to do more.&lt;/p&gt;

&lt;p&gt;It turns PHP’s &lt;code&gt;define()&lt;/code&gt; into a sandbox of potential, one where &lt;strong&gt;constants aren't constants… until they are.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  About the Author
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Jérémie Fréreault&lt;/strong&gt; is the creator of &lt;a href="https://github.com/jeremie5/dataphyre" rel="noopener noreferrer"&gt;Dataphyre&lt;/a&gt; and &lt;a href="https://shopiro.ca" rel="noopener noreferrer"&gt;Shopiro&lt;/a&gt;, building from-scratch systems with zero third-party lock-in, brutal scalability, and a deep love for elegant engineering. He also occasionally weaponizes physics metaphors in production code. This is one of those times.&lt;/p&gt;

&lt;p&gt;License: &lt;a href="https://github.com/jeremie5/dataphyre?tab=License-1-ov-file" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;  &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>programming</category>
      <category>php</category>
      <category>humor</category>
    </item>
    <item>
      <title>Inside Shopiro's CORTEX: The Ontology Engine Powering The Future of Intelligent Commerce</title>
      <dc:creator>Jérémie Fréreault</dc:creator>
      <pubDate>Mon, 07 Apr 2025 05:11:44 +0000</pubDate>
      <link>https://dev.to/jrmie_frreault_9f39816/inside-shopiros-cortex-the-ontology-engine-powering-the-future-of-intelligent-commerce-23ho</link>
      <guid>https://dev.to/jrmie_frreault_9f39816/inside-shopiros-cortex-the-ontology-engine-powering-the-future-of-intelligent-commerce-23ho</guid>
      <description>&lt;p&gt;In the vast universe of e-commerce platforms, product discovery is often reduced to text-matching or crude filters. At Shopiro, we chose a different path. We built &lt;strong&gt;CORTEX&lt;/strong&gt; — our &lt;strong&gt;Computational Ontology for Relational Tracking and Explainability&lt;/strong&gt; — a modular reasoning engine that turns product data into real-time semantic intelligence.&lt;/p&gt;

&lt;p&gt;Unlike traditional faceted search or keyword parsing, &lt;strong&gt;CORTEX understands&lt;/strong&gt; what a product is, how it relates to others, and why a buyer might care.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why CORTEX Exists
&lt;/h2&gt;

&lt;p&gt;Online marketplaces handle millions of listings, each rich in unstructured or loosely structured data. &lt;strong&gt;CORTEX's role is to&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Extract filterable dimensions from listings
&lt;/li&gt;
&lt;li&gt;Normalize values across international units (e.g. PSI to kPa, inches to mm)
&lt;/li&gt;
&lt;li&gt;Build compatibility rules between products (e.g. &lt;em&gt;“will this battery fit my drone?”&lt;/em&gt;)
&lt;/li&gt;
&lt;li&gt;Allow prompt-driven expansion of ontologies using LLMs
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of this occurs behind the scenes, before a user ever sees a filter or suggestion — within milliseconds.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Brain: Attribute Definitions &amp;amp; Property Types
&lt;/h2&gt;

&lt;p&gt;At the heart of CORTEX are two key constructs:&lt;/p&gt;

&lt;h3&gt;
  
  
  Attribute Definitions
&lt;/h3&gt;

&lt;p&gt;These describe individual data points — like &lt;code&gt;max_speed_kph&lt;/code&gt;, &lt;code&gt;has_bluetooth&lt;/code&gt;, or &lt;code&gt;battery_capacity_mah&lt;/code&gt;. Each attribute includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Human-readable label and description
&lt;/li&gt;
&lt;li&gt;Data type (&lt;code&gt;float&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;, &lt;code&gt;enum&lt;/code&gt;, etc.)
&lt;/li&gt;
&lt;li&gt;SI normalization unit (optional)
&lt;/li&gt;
&lt;li&gt;Validation rules and regexes
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  User Property Types
&lt;/h3&gt;

&lt;p&gt;These define kinds of products (e.g. &lt;code&gt;"cordless_drill"&lt;/code&gt;, &lt;code&gt;"quad_core_cpu"&lt;/code&gt;) and include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Schema of required/optional attributes
&lt;/li&gt;
&lt;li&gt;Parent/child product relationships
&lt;/li&gt;
&lt;li&gt;Match logic (e.g. &lt;code&gt;&amp;gt;=&lt;/code&gt;, &lt;code&gt;!=&lt;/code&gt;, or tolerance-based compatibility)&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  How Filters Are Built
&lt;/h2&gt;

&lt;p&gt;Whenever listings are viewed, CORTEX can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Aggregate their &lt;code&gt;ontology_cache&lt;/code&gt; fields
&lt;/li&gt;
&lt;li&gt;Infer filter types (&lt;code&gt;enum&lt;/code&gt;, &lt;code&gt;float&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;)
&lt;/li&gt;
&lt;li&gt;Normalize units when requested
&lt;/li&gt;
&lt;li&gt;Include attribute metadata (label, unit, enum list, etc.)
&lt;/li&gt;
&lt;li&gt;Sort values by popularity or alphabetically
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These dynamic filters reflect &lt;strong&gt;real listings&lt;/strong&gt;, not static category trees. And because they are schema-aware, we can prevent filter bloat by collapsing or pruning weak signals.&lt;/p&gt;




&lt;h2&gt;
  
  
  Compatibility Logic
&lt;/h2&gt;

&lt;p&gt;CORTEX supports parent-child product matching. For instance:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;"Is this CPU compatible with the motherboard I bought last week?"&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;CORTEX checks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Shared attribute codes across types
&lt;/li&gt;
&lt;li&gt;Normalized values and operators (e.g. RAM speed must be &amp;gt;= 2400MHz)
&lt;/li&gt;
&lt;li&gt;Optional explanation output (e.g. &lt;code&gt;"Mismatch: PCIe slot not present"&lt;/code&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This logic is abstracted so it can run on &lt;strong&gt;any listing-property pair&lt;/strong&gt; — even user-defined setups.&lt;/p&gt;




&lt;h2&gt;
  
  
  A Foundation, Not a Feature
&lt;/h2&gt;

&lt;p&gt;CORTEX is &lt;strong&gt;not a plugin or a UX layer&lt;/strong&gt; — it is &lt;strong&gt;foundational&lt;/strong&gt;. Its outputs inform:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Search ranking
&lt;/li&gt;
&lt;li&gt;Compatibility badges
&lt;/li&gt;
&lt;li&gt;Filter interfaces
&lt;/li&gt;
&lt;li&gt;Recommendation logic
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In short: &lt;strong&gt;CORTEX is how Shopiro thinks&lt;/strong&gt;. Every product, every query, every match — grounded in ontological logic.&lt;/p&gt;




&lt;p&gt;&lt;a href="https://shopiro.ca" rel="noopener noreferrer"&gt;https://shopiro.ca&lt;/a&gt;: &lt;em&gt;The new smart way to shop online™&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
