<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Debugging | Nerdpress.org</title>
	<atom:link href="https://nerdpress.org/tag/debugging/feed/" rel="self" type="application/rss+xml" />
	<link>https://nerdpress.org</link>
	<description>...dev, tech problems and solutions.</description>
	<lastBuildDate>Thu, 16 Apr 2026 14:19:33 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.5</generator>
	<item>
		<title>PHP&#8217;s serialize_precision hidden danger</title>
		<link>https://nerdpress.org/2026/04/16/phps-serialize_precision-hidden-danger/</link>
		
		<dc:creator><![CDATA[Ivo Bathke]]></dc:creator>
		<pubDate>Thu, 16 Apr 2026 14:19:02 +0000</pubDate>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[JSON]]></category>
		<guid isPermaLink="false">https://nerdpress.org/?p=3477</guid>

					<description><![CDATA[<p>The PHP configuration directive serialize_precision can cause hard to debug issues. When deviated from its default value, it can lead to inexpected behavior in common functions like json_encode() and serialize(). The Problem If you change the serialize_precision setting from its default value of -1, the float precision will be more digits than 2 decimal places.If &#8230; </p>
<p class="link-more"><a href="https://nerdpress.org/2026/04/16/phps-serialize_precision-hidden-danger/" class="more-link">Continue reading<span class="screen-reader-text"> "PHP&#8217;s serialize_precision hidden danger"</span></a></p>
The post <a href="https://nerdpress.org/2026/04/16/phps-serialize_precision-hidden-danger/">PHP’s serialize_precision hidden danger</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></description>
										<content:encoded><![CDATA[<p>The PHP configuration directive <code>serialize_precision</code> can cause hard to debug issues.</p>



<p>When deviated from its default value, it can lead to inexpected behavior in common functions like <code>json_encode()</code> and <code>serialize()</code>.</p>



<span id="more-3477"></span>



<h2 class="wp-block-heading"><strong>The Problem</strong></h2>



<p>If you change the <code>serialize_precision</code> setting from its default value of <strong>-1</strong>, the float precision will be more digits than 2 decimal places.<br />If you are not aware of this setting, it can lead to hard-to-debug issues in your application.</p>



<p>This behavior can silently break payload validation, API responses, or any logic that relies on exact string comparisons of numeric values or which assumes that float values come with 2 decimal places.</p>



<h2 class="wp-block-heading"><strong>Impact on Functions</strong></h2>



<p>When <code>serialize_precision</code> is set to something other than <strong>-1</strong>, the following functions are affected:</p>



<ul class="wp-block-list">
<li>json_encode()</li>



<li>json_decode()</li>



<li>serialize()</li>



<li>unserialize()</li>
</ul>



<p>Consider the following example.<br />Setting a high precision changes the number in the JSON output:</p>


<pre class="wp-block-code"><span><code class="hljs language-xml"><span class="php"><span class="hljs-meta">&lt;?php</span>
<span class="hljs-comment">// High precision</span>
ini_set(<span class="hljs-string">"serialize_precision"</span>, <span class="hljs-number">100</span>);
<span class="hljs-keyword">echo</span> json_encode(<span class="hljs-number">12.12</span>);
<span class="hljs-comment">// Output: 12.1199999999999992184029906638897955417633056640625</span>

<span class="hljs-comment">// Default (recommended) precision</span>
ini_set(<span class="hljs-string">"serialize_precision"</span>, <span class="hljs-number">-1</span>);
<span class="hljs-keyword">echo</span> json_encode(<span class="hljs-number">12.12</span>);
<span class="hljs-comment">// Output: 12.12</span></span></code></span></pre>


<h2 class="wp-block-heading"><strong>How to Check Your Configuration</strong></h2>



<p>So better verify your current setting, especially when dealing with mysterious floating-point issues in legacy environments.<br />When on shared hosting, you might even not know that the setting was changed.</p>



<p>You can check it via code:</p>


<pre class="wp-block-code"><span><code class="hljs language-php"><span class="hljs-keyword">echo</span> ini_get(<span class="hljs-string">"serialize_precision"</span>);</code></span></pre>


<p>Or, if you are using PHP 8.5 or newer, you can conveniently check for configuration differences using the CLI:</p>


<pre class="wp-block-code"><span><code class="hljs">php --ini=diff</code></span></pre>


<p>This will highlight any settings that differ from the PHP defaults, making it much easier to spot such dangerous configurations.</p>



<h2 class="wp-block-heading"><strong>Conclusion</strong></h2>



<p>If you encounter unexpected floating-point behavior in your PHP application, check the <code>serialize_precision</code> setting first. It&#8217;s a simple fix that can save you hours of debugging.</p>



<p></p>The post <a href="https://nerdpress.org/2026/04/16/phps-serialize_precision-hidden-danger/">PHP’s serialize_precision hidden danger</a> first appeared on <a href="https://nerdpress.org">Nerdpress.org</a>.]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
