{"id":7304,"date":"2023-04-28T08:29:01","date_gmt":"2023-04-28T13:29:01","guid":{"rendered":"https:\/\/justinparrtech.com\/JustinParr-Tech\/?p=7304"},"modified":"2023-04-28T08:29:01","modified_gmt":"2023-04-28T13:29:01","slug":"the-dangers-of-old-code-a-cautionary-tale","status":"publish","type":"post","link":"https:\/\/justinparrtech.com\/JustinParr-Tech\/the-dangers-of-old-code-a-cautionary-tale\/","title":{"rendered":"The Dangers of Old Code &#8211; A Cautionary Tale"},"content":{"rendered":"<p>Two bad lines of code took this entire site down.\u00a0 Here is what you can learn from my mistake.<\/p>\n<p><!--more--><\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\"><p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<\/div><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/justinparrtech.com\/JustinParr-Tech\/the-dangers-of-old-code-a-cautionary-tale\/#here-is-what-happened\" >Here is What Happened<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/justinparrtech.com\/JustinParr-Tech\/the-dangers-of-old-code-a-cautionary-tale\/#here-is-what-i-learned-and-how-i-fixed-it\" >Here is What I Learned, and How I Fixed It.<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/justinparrtech.com\/JustinParr-Tech\/the-dangers-of-old-code-a-cautionary-tale\/#the-moral-of-the-story\" >The Moral of the Story<\/a><\/li><\/ul><\/nav><\/div>\n\n<p>&nbsp;<\/p>\n<h2><span class=\"ez-toc-section\" id=\"here-is-what-happened\"><\/span>Here is What Happened<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Apparently, at some point late Friday night, my hosting provider upgraded to a newer version of PHP.\u00a0 When I checked my site Saturday morning, all I could get was &#8220;There has been a critical error on your website.&#8221; in a neatly-formatted box.<\/p>\n<p>Uh oh.<\/p>\n<p>&nbsp;<\/p>\n<h2><span class=\"ez-toc-section\" id=\"here-is-what-i-learned-and-how-i-fixed-it\"><\/span>Here is What I Learned, and How I Fixed It.<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>I had an older table of contents plugin that used deprecated syntax for accessing characters within a string, and that older syntax is now no longer supported in the newer version of PHP:<\/p>\n<pre>Deprecated Syntax:\r\n<span style=\"color: #ffff00;\">MyString{Index}<\/span>\r\n\r\nProper Syntax:\r\n<span style=\"color: #00ff00;\">MyString[Index]<\/span><\/pre>\n<p>The plugin in question used the deprecated syntax in two places, which was now throwing a hard error instead of just ignoring as it had previously done.<\/p>\n<p>Even after I fixed the two syntax errors, I had some kind of weird memory allocation problem, so I ended up just disabling the plugin, which at least restored my site.<\/p>\n<p>As it turns out, the plugin I&#8217;m using is no longer being maintained.\u00a0 Even if I fix\u00a0<em>this<\/em> problem, I run the risk that I will have some\u00a0<em>other<\/em> problem later, for the same reason.<\/p>\n<p><strong>So rather than fix someone else&#8217;s old code or write my own, I searched for a replacement.\u00a0 At least for now.<\/strong><\/p>\n<p>Ideally, I wanted an exact replacement:<\/p>\n<ul>\n<li>Light weight and simple to use<\/li>\n<li>Free for non-commercial use \/ GPL \/ LGPL<\/li>\n<li>Same integration features &#8211; namely via &#8220;toc&#8221; shortcode<\/li>\n<li>Same functionality:\n<ul>\n<li>Produces a table of contents automatically by selectively including header styles and other styles<\/li>\n<li>Produces multi-level section numbering (e.g. 1, 1.1, 1.1.1, etc&#8230;)<\/li>\n<li>Prepends the section number in front of the actual header text within the body of the post<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>To my surprise, there are <strong>not<\/strong> many options that are free AND simple AND work as requested, but I finally found one that was close. Although the plugin builds the table as expected, it doesn&#8217;t number the header text within the body.<\/p>\n<p>So, I added some CSS numbering, only to find out that WordPress uses some of the same header styles to render the page itself &#8211; for example, the post title uses &lt;H2&gt;, and so does the blog&#8217;s tagline.\u00a0 So some\u00a0<em>selective<\/em> CSS numbering later, I finally got it working.<\/p>\n<p>For reference, in case anyone needs it:<\/p>\n<pre>body {\r\n    counter-reset: h2cc;\r\n<span style=\"color: #99ccff;\">\/* <\/span>\r\n<span style=\"color: #99ccff;\">In theory, I don't need h3 through h6 here, because <\/span>\r\n<span style=\"color: #99ccff;\">I'm resetting the next level down within the header itself.  <\/span>\r\n<span style=\"color: #99ccff;\">However, this is the only way I could get it to work properly <\/span>\r\n<span style=\"color: #99ccff;\">*\/<\/span>\r\n    counter-reset: h3cc;\r\n    counter-reset: h4cc;\r\n    counter-reset: h5cc;\r\n    counter-reset: h6cc;\r\n}\r\nh2 {\r\n    counter-reset: h3cc;\r\n}\r\nh2:before {\r\n    content: counter(h2cc) \". \";\r\n    counter-increment: h2cc;\r\n}\r\nh2.entry-title:before {\r\n<span style=\"color: #99ccff;\">\/*<\/span>\r\n<span style=\"color: #99ccff;\">Special case for post title.  Because<\/span>\r\n<span style=\"color: #99ccff;\">this hits AFTER the body, I had to add<\/span>\r\n<span style=\"color: #99ccff;\">a negative increment, or my numbering<\/span>\r\n<span style=\"color: #99ccff;\">started with 2.<\/span>\r\n<span style=\"color: #99ccff;\">*\/<\/span>\r\n    content: none;\r\n    counter-increment: h2cc -1;\r\n}\r\nh2#site-description:before, h2.widget-title:before, h2#comments-title:before {\r\n<span style=\"color: #99ccff;\">\/*<\/span>\r\n<span style=\"color: #99ccff;\">Special cases for tagline, widget (side bar) titles, and comment section title.<\/span>\r\n<span style=\"color: #99ccff;\">*\/<\/span>\r\n    content: none;\r\n}\r\nh3 {\r\n    counter-reset: h4cc;\r\n}\r\nh3:before {\r\n    content: counter(h2cc) \".\" counter(h3cc) \". \";\r\n    counter-increment: h3cc;\r\n}\r\nh3#reply-title.comment-reply-title:before {\r\n<span style=\"color: #99ccff;\">\/*<\/span> \r\n<span style=\"color: #99ccff;\">Special case for each comment's title.<\/span> \r\n<span style=\"color: #99ccff;\">*\/<\/span>\r\n    content:none;\r\n}\r\nh4 {\r\n    counter-reset: h5cc;\r\n}\r\nh4:before {\r\n    content: counter(h2cc) \".\" counter(h3cc) \".\" counter(h4cc) \". \";\r\n    counter-increment: h4cc;\r\n}\r\nh5 {\r\n    counter-reset: h6cc;\r\n}\r\nh5:before {\r\n    content: counter(h2cc) \".\" counter(h3cc) \".\" counter(h4cc) \".\" counter(h5cc) \". \";\r\n    counter-increment: h5cc;\r\n}\r\nh6:before {\r\n    content: counter(h2cc) \".\" counter(h3cc) \".\" counter(h4cc) \".\" counter(h5cc) \".\" counter(h6cc) \". \";\r\n    counter-increment: h6cc;\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<h2><span class=\"ez-toc-section\" id=\"the-moral-of-the-story\"><\/span>The Moral of the Story<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>I run in to situations all the time where old code is no longer being maintained, and therefore can&#8217;t be upgraded to newer operating systems, databases, nor patched to current because the code breaks.<\/p>\n<p><strong>&#8220;Just run the old code inside an older environment&#8221;<\/strong><\/p>\n<p style=\"padding-left: 40px;\"><em>&#8211; Developer mistake #101<\/em><\/p>\n<p>Although this is a short-term fix &#8211; I could have downgraded to an older PHP &#8211; it doesn&#8217;t\u00a0<em>solve<\/em> the underlying problem, which is that the threat landscape is constantly changing, and the only way the vendors can keep up is to deprecate older operating systems and components.\u00a0 They shouldn&#8217;t be expected to fix a brand-new problem on a component which itself is now many versions old.<\/p>\n<p><strong>The only viable approach is to ensure that every bit of code you are using is currently being maintained<\/strong>.\u00a0 From the code within your application, to the code inside your operating systems and databases, everything needs to be supported.<\/p>\n<ul>\n<li>Bring older code up to date with newer standards<\/li>\n<li>Replace older components with newer ones<\/li>\n<li>Plan for life cycles and future standards<\/li>\n<\/ul>\n<p>After having written quite a bit about developer mistakes, I was surprised that I made this simple mistake.\u00a0 Although I don&#8217;t run any kind of critical code, and at the end of the day, the only impact was that my website was down for a few hours, I wanted to share my experiences and lessons learned.<\/p>\n<p>If you want to read about other common developer mistakes, here is a list:<\/p>\n<ul>\n<li><a href=\"https:\/\/justinparrtech.com\/JustinParr-Tech\/top-developer-mistakes\/\">Top Developer Mistakes<\/a><\/li>\n<li><a href=\"https:\/\/justinparrtech.com\/JustinParr-Tech\/more-common-developer-mistakes\/\">More Common Developer Mistakes<\/a><\/li>\n<li><a href=\"https:\/\/justinparrtech.com\/JustinParr-Tech\/common-website-design-mistakes\/\">Common Website Design Mistakes<\/a><\/li>\n<li><a href=\"https:\/\/justinparrtech.com\/JustinParr-Tech\/the-log4j-problem-was-both-insidious-and-unnecessary\/\">The Log4J Problem Was Both Insidious And Unnecessary<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Two bad lines of code took this entire site down.\u00a0 Here is what you can learn from my mistake.<\/p>\n","protected":false},"author":16,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17],"tags":[],"class_list":["post-7304","post","type-post","status-publish","format-standard","hentry","category-good-design-bad-design"],"_links":{"self":[{"href":"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-json\/wp\/v2\/posts\/7304","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-json\/wp\/v2\/users\/16"}],"replies":[{"embeddable":true,"href":"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-json\/wp\/v2\/comments?post=7304"}],"version-history":[{"count":10,"href":"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-json\/wp\/v2\/posts\/7304\/revisions"}],"predecessor-version":[{"id":7317,"href":"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-json\/wp\/v2\/posts\/7304\/revisions\/7317"}],"wp:attachment":[{"href":"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-json\/wp\/v2\/media?parent=7304"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-json\/wp\/v2\/categories?post=7304"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/justinparrtech.com\/JustinParr-Tech\/wp-json\/wp\/v2\/tags?post=7304"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}