28.xhtml 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. h t t :: / / t /
  4. h t t :: // // t //
  5. h ttttt ttttt ppppp sssss // // y y sssss ttttt //
  6. hhhh t t p p s // // y y s t //
  7. h hh t t ppppp sssss // // yyyyy sssss t //
  8. h h t t p s :: / / y .. s t .. /
  9. h h t t p sssss :: / / yyyyy .. sssss t .. /
  10. <https://y.st./>
  11. Copyright © 2016 Alex Yst <mailto:copyright@y.st>
  12. This program is free software: you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation, either version 3 of the License, or
  15. (at your option) any later version.
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. GNU General Public License for more details.
  20. You should have received a copy of the GNU General Public License
  21. along with this program. If not, see <https://www.gnu.org./licenses/>.
  22. -->
  23. <!DOCTYPE html>
  24. <html xmlns="http://www.w3.org/1999/xhtml">
  25. <head>
  26. <base href="https://y.st./en/weblog/2016/11-November/28.xhtml" />
  27. <title>I learned the secret to protecting values from closures. &lt;https://y.st./en/weblog/2016/11-November/28.xhtml&gt;</title>
  28. <link rel="icon" type="image/png" href="/link/CC_BY-SA_4.0/y.st./icon.png" />
  29. <link rel="stylesheet" type="text/css" href="/link/basic.css" />
  30. <link rel="stylesheet" type="text/css" href="/link/site-specific.css" />
  31. <script type="text/javascript" src="/script/javascript.js" />
  32. <meta name="viewport" content="width=device-width" />
  33. </head>
  34. <body>
  35. <nav>
  36. <p>
  37. <a href="/en/">Home</a> |
  38. <a href="/en/a/about.xhtml">About</a> |
  39. <a href="/en/a/contact.xhtml">Contact</a> |
  40. <a href="/a/canary.txt">Canary</a> |
  41. <a href="/en/URI_research/"><abbr title="Uniform Resource Identifier">URI</abbr> research</a> |
  42. <a href="/en/opinion/">Opinions</a> |
  43. <a href="/en/coursework/">Coursework</a> |
  44. <a href="/en/law/">Law</a> |
  45. <a href="/en/a/links.xhtml">Links</a> |
  46. <a href="/en/weblog/2016/11-November/28.xhtml.asc">{this page}.asc</a>
  47. </p>
  48. <hr/>
  49. <p>
  50. Weblog index:
  51. <a href="/en/weblog/"><abbr title="American Standard Code for Information Interchange">ASCII</abbr> calendars</a> |
  52. <a href="/en/weblog/index_ol_ascending.xhtml">Ascending list</a> |
  53. <a href="/en/weblog/index_ol_descending.xhtml">Descending list</a>
  54. </p>
  55. <hr/>
  56. <p>
  57. Jump to entry:
  58. <a href="/en/weblog/2015/03-March/07.xhtml">&lt;&lt;First</a>
  59. <a rel="prev" href="/en/weblog/2016/11-November/27.xhtml">&lt;Previous</a>
  60. <a rel="next" href="/en/weblog/2016/11-November/29.xhtml">Next&gt;</a>
  61. <a href="/en/weblog/latest.xhtml">Latest&gt;&gt;</a>
  62. </p>
  63. <hr/>
  64. </nav>
  65. <header>
  66. <h1>I learned the secret to protecting values from closures.</h1>
  67. <p>Day 00632: Monday, 2016 November 28</p>
  68. </header>
  69. <img src="/img/CC_BY-SA_4.0/y.st./weblog/2016/11/28.jpg" alt="A gated apartment complex" class="weblog-header-image" width="811" height="480" />
  70. <h2 id="general">General news</h2>
  71. <p>
  72. After my alarm went off, I must have fallen back asleep.
  73. It only felt like I continued laying down for a couple of minutes, but the next thing that I knew, more than half an hour had passed.
  74. I ended up having to skip picking up lunch on my way to work, and I still clocked in five minutes late.
  75. I made up for it though by staying an extra half hour when the shift leader in charge needed some extra manpower while waiting for the rest of the night crew to arrive.
  76. </p>
  77. <p>
  78. Professor Shyguy just opened preorders for their new album, <a href="https://professorshyguy.bandcamp.com/album/merry-chipmas-v-2">Merry Chipmas v.2</a>.
  79. Unlike the original Merry Chipmas, which was labeled as having all rights reserved, this album is covered by the <abbr title="Creative Commons Attribution 3.0 Unported">CC BY 3.0</abbr> license! It appears to have the original five songs from the first album, plus five more.
  80. Speaking of the first album, it&apos;s gone missing.
  81. Professor Shyguy has taken it off the market.
  82. The new album is scheduled to be released on 2016-12-01.
  83. </p>
  84. <p>
  85. My <a href="/a/canary.txt">canary</a> still sings the tune of freedom and transparency.
  86. </p>
  87. <h2 id="include.d"><a href="https://git.volatile.ch./y.st./include.d/releases">include.d</a></h2>
  88. <p>
  89. What if <abbr title="Uniform Resource Identifier">URI</abbr> components are stored in a static variable within a method? Is that possible? Would different instances of the class have different values in their static variables? Would closures be able to tamper with this variable? These are the questions that haunted me after I had a sudden flash of inspiration early this morning.
  90. As far as I can tell, there isn&apos;t a way for closures to tamper with this variable, provided that all of the normalization and validation features are supplied within the method itself.
  91. However, all instances of the class share a single copy of the variable.
  92. This can easily be fixed by making the variable an array and finding some way of granting each instance of the class a unique key.
  93. The key itself doesn&apos;t even need to be protected from closures.
  94. If closures tamper with the key, two objects will either share the same values or one object will have a bad key.
  95. I can either set the storage method to recover by assigning a default key or allow such objects to simply be broken.
  96. As long as no existing data set used by the class contains invalid <abbr title="Uniform Resource Identifier">URI</abbr> components, or a combination of valid <abbr title="Uniform Resource Identifier">URI</abbr> components that are invalid when used together, everything is awesome.
  97. Lastly, this tactic completely breaks the <code>\var_export()</code> function, as <code>\var_export()</code> won&apos;t see the data any more; after all, it won&apos;t be stored in properties at that point.
  98. I should probably implement some sort of workaround.
  99. One possibility would be to put a string copy of the <abbr title="Uniform Resource Identifier">URI</abbr> in a property.
  100. Closures would have access to this and be able to bork it, but that&apos;s about the best that I can do.
  101. </p>
  102. <p>
  103. The realization of how I might need to fix up my <abbr title="Uniform Resource Identifier">URI</abbr> classes once again came right after I finished bringing the <code>\st\y\uri\gopher</code> class up to speed with my last <abbr title="application programming interface">API</abbr> update.
  104. At first, I was thinking that hopefully not too much of my last <abbr title="application programming interface">API</abbr> update will go to waste.
  105. It&apos;s really a shame that I even have to jump through all these hoops just to keep my <abbr title="application programming interface">API</abbr> from being broken.
  106. Closures should not be allowed to break basic <abbr title="application programming interface">API</abbr> features.
  107. After thinking about his all day though, I came to the conclusion that it simply isn&apos;t worth it to work around this bug.
  108. Using a static variable containing an array would certainly have the effect that I&apos;m after, however, it breaks cloning and deconstructing features that are built into basic <abbr title="PHP: Hypertext Preprocessor">PHP</abbr> objects.
  109. I&apos;d have to do all cloning manually, which would certainly make my code less efficient, and if I failed to implement deconstructing manually, all past object data would be saved even after the objects are deleted.
  110. On a longer-running script that uses a lot of <abbr title="Uniform Resource Identifier">URI</abbr> objects, such as my onion spider, memory would fill up.
  111. You can&apos;t break my <abbr title="Uniform Resource Identifier">URI</abbr> objects accidentally, at least not with this closure feature.
  112. If you break my <abbr title="Uniform Resource Identifier">URI</abbr> objects in your script by using closures on them, you&apos;ve done it with intent to make the code fail.
  113. As such, I&apos;m just going to leave it alone.
  114. It&apos;s the problem of whoever causes it, not me.
  115. Now that I know how to protect variables, I can stop obsessing over this.
  116. </p>
  117. <p>
  118. I&apos;ve been working on my big <abbr title="Uniform Resource Identifier">URI</abbr> update for a while now.
  119. This update adds all scheme-specific <abbr title="Uniform Resource Identifier">URI</abbr> syntaxes to include.d as classes.
  120. However, this is boring.
  121. Educational, but very, very boring.
  122. I&apos;ve decided to attack the problem of scheme-specific <abbr title="Uniform Resource Identifier">URI</abbr> syntax in a different way.
  123. Instead of one big update, I&apos;ll add a few <abbr title="Uniform Resource Identifier">URI</abbr> schemes to each update.
  124. If the update is a 0.0.0.1-level or higher update, I&apos;ll add at least one permanent scheme, at least one historic scheme, and at least one provisional scheme.
  125. If I don&apos;t have those ready yet, I won&apos;t make a release yet.
  126. If I <strong>*do*</strong> have them ready though, I can (but do not have to) ignore the <abbr title="Uniform Resource Identifier">URI</abbr> code for the time being.
  127. Updates that are 0.0.0.0.1-level or below updates will be prohibited from introducing new <abbr title="Uniform Resource Identifier">URI</abbr> scheme classes.
  128. </p>
  129. <h2 id="apartment">Apartment hunting</h2>
  130. <p>
  131. I went to the apartment complex at which I filed my initial housing application, and had them update the telephone number that they have on file for me.
  132. Now if Google does end up revoking the telephone number that they issued me, the damage will be limited.
  133. </p>
  134. <hr/>
  135. <p>
  136. Copyright © 2016 Alex Yst;
  137. You may modify and/or redistribute this document under the terms of the <a rel="license" href="/license/gpl-3.0-standalone.xhtml"><abbr title="GNU&apos;s Not Unix">GNU</abbr> <abbr title="General Public License version Three or later">GPLv3+</abbr></a>.
  138. If for some reason you would prefer to modify and/or distribute this document under other free copyleft terms, please ask me via email.
  139. My address is in the source comments near the top of this document.
  140. This license also applies to embedded content such as images.
  141. For more information on that, see <a href="/en/a/licensing.xhtml">licensing</a>.
  142. </p>
  143. <p>
  144. <abbr title="World Wide Web Consortium">W3C</abbr> standards are important.
  145. This document conforms to the <a href="https://validator.w3.org./nu/?doc=https%3A%2F%2Fy.st.%2Fen%2Fweblog%2F2016%2F11-November%2F28.xhtml"><abbr title="Extensible Hypertext Markup Language">XHTML</abbr> 5.1</a> specification and uses style sheets that conform to the <a href="http://jigsaw.w3.org./css-validator/validator?uri=https%3A%2F%2Fy.st.%2Fen%2Fweblog%2F2016%2F11-November%2F28.xhtml"><abbr title="Cascading Style Sheets">CSS</abbr>3</a> specification.
  146. </p>
  147. </body>
  148. </html>