<?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: Hideaki</title>
    <description>The latest articles on DEV Community by Hideaki (@hideaki_shimizu_75b25756f).</description>
    <link>https://dev.to/hideaki_shimizu_75b25756f</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%2F3128849%2F4954c8be-f807-4369-ad83-4d05930a2faf.png</url>
      <title>DEV Community: Hideaki</title>
      <link>https://dev.to/hideaki_shimizu_75b25756f</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hideaki_shimizu_75b25756f"/>
    <language>en</language>
    <item>
      <title>Creating a PHP, Go, and Python Quine Relay</title>
      <dc:creator>Hideaki</dc:creator>
      <pubDate>Wed, 11 Feb 2026 14:42:35 +0000</pubDate>
      <link>https://dev.to/hideaki_shimizu_75b25756f/developing-a-php-go-and-python-quine-relay-59g3</link>
      <guid>https://dev.to/hideaki_shimizu_75b25756f/developing-a-php-go-and-python-quine-relay-59g3</guid>
      <description>&lt;p&gt;I have created a Quine relay involving PHP, Go, and Python, and I’m here to explain how it works.&lt;br&gt;
This is the code for &lt;code&gt;QuineRelay.php&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?=&lt;/span&gt;&lt;span class="k"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'print "package main;import\42fmt\42;func main(){fmt.Print(\140print(r\47\47\47&amp;lt;?=eval(\44_=\47$_\47);\47\47\47)\140)}";'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yes, it probably looks like total nonsense. I will explain it step by step.&lt;br&gt;
Now, you can see many things like &lt;code&gt;\42&lt;/code&gt;. In PHP, inside double quotes, these are treated as octal ASCII codes and converted into characters.&lt;br&gt;
For example, a double quote is ASCII code 34, which is 42 in octal.&lt;br&gt;
Therefore, &lt;code&gt;\42&lt;/code&gt; will be a double quote.&lt;/p&gt;

&lt;p&gt;I have created a conversion table below:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Octal&lt;/th&gt;
&lt;th&gt;ASCII Code&lt;/th&gt;
&lt;th&gt;Character&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;42&lt;/td&gt;
&lt;td&gt;34&lt;/td&gt;
&lt;td&gt;" (Double Quote)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;47&lt;/td&gt;
&lt;td&gt;39&lt;/td&gt;
&lt;td&gt;' (Single Quote)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;140&lt;/td&gt;
&lt;td&gt;96&lt;/td&gt;
&lt;td&gt;Backtick&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;(I couldn't put the actual backtick in the table without breaking the markdown 😅)&lt;/p&gt;

&lt;p&gt;The advantage of using this octal notation is that these characters do not need to be escaped when they are included in Go or Python strings.&lt;br&gt;
The difficult part of a Quine is how to handle characters like double quotes or single quotes that require escaping when they appear within a string, but by using octal notation, the need for escaping is eliminated.&lt;/p&gt;

&lt;p&gt;Now, notice that the variable &lt;code&gt;$_&lt;/code&gt; is declared as an argument for the &lt;code&gt;eval&lt;/code&gt; function at the beginning.&lt;br&gt;
Let's look at the content of variable &lt;code&gt;$_&lt;/code&gt;. Since &lt;code&gt;$_&lt;/code&gt; is enclosed in single quotes, the octal notation is treated literally as backslashes and numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;// inside $_&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="s2"&gt;"package main;import&lt;/span&gt;&lt;span class="se"&gt;\42&lt;/span&gt;&lt;span class="s2"&gt;fmt&lt;/span&gt;&lt;span class="se"&gt;\42&lt;/span&gt;&lt;span class="s2"&gt;;func main()&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;fmt.Print(\140print(r\47\47\47&amp;lt;?=eval(\44_=\47$_\47);\47\47\47)\140)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code is then &lt;code&gt;eval&lt;/code&gt;'ed. Since the string passed to &lt;code&gt;print&lt;/code&gt; is enclosed in double quotes, the conversion from octal to ASCII occurs this time.&lt;br&gt;
Also, &lt;code&gt;$_&lt;/code&gt; appears toward the end within the double quotes. In PHP, variable names inside double quotes are expanded with the value, so the second &lt;code&gt;$_&lt;/code&gt; will be expanded as the actual content of the variable.&lt;br&gt;
The expansion of this &lt;code&gt;$_&lt;/code&gt; is the key trick to this Quine.&lt;br&gt;
Running this PHP code outputs the following Go code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;package&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="s"&gt;"fmt"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="k"&gt;func&lt;/span&gt; &lt;span class="n"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(){&lt;/span&gt;&lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;`print(r'''&amp;lt;?=eval($_='print "package main;import\42fmt\42;func main(){fmt.Print(\140print(r\47\47\47&amp;lt;?=eval(\44_=\47$_\47);\47\47\47)\140)}";');''')`&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Since escaping line breaks is difficult, I used semicolons to make it a one-liner of Go (When you write Go, you don't usually use semicolons at the end of statements, but Go compiler apparently adds them. Here I add semicolons manually to achieve the one-liner).&lt;br&gt;
Also, by using backticks for the string, I can include single and double quotes within the string.&lt;/p&gt;

&lt;p&gt;Running this Go code outputs the following Python code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;r&lt;/span&gt;&lt;span class="sh"&gt;'''&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?=eval($_=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;print &lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;package main;import\42fmt\42;func main(){fmt.Print(\140print(r\47\47\47&amp;lt;?=eval(\44_=\47$_\47);\47\47\47)\140)}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;);&lt;/span&gt;&lt;span class="sh"&gt;'''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is relatively straightforward, but by using &lt;code&gt;'''&lt;/code&gt;, I can use single quotes within the string, and by using &lt;code&gt;r'''&lt;/code&gt;, I avoid the conversion from octal to ASCII.&lt;/p&gt;

&lt;p&gt;Running this Python code brings us back to the original PHP.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?=&lt;/span&gt;&lt;span class="k"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$_&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'print "package main;import\42fmt\42;func main(){fmt.Print(\140print(r\47\47\47&amp;lt;?=eval(\44_=\47$_\47);\47\47\47)\140)}";'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Summary
&lt;/h2&gt;

&lt;p&gt;I thought a three-language Quine relay would be very difficult, but once I started writing it, it turned out to be simpler than expected.&lt;br&gt;
I hope this article helps you read/write more quines 🙂&lt;/p&gt;

</description>
      <category>go</category>
      <category>php</category>
      <category>python</category>
    </item>
    <item>
      <title>Encoding an Encoder for my own Encoding with the Encoder</title>
      <dc:creator>Hideaki</dc:creator>
      <pubDate>Tue, 27 Jan 2026 09:06:11 +0000</pubDate>
      <link>https://dev.to/hideaki_shimizu_75b25756f/encoding-an-encoder-for-my-own-encoding-with-the-encoder-2c1c</link>
      <guid>https://dev.to/hideaki_shimizu_75b25756f/encoding-an-encoder-for-my-own-encoding-with-the-encoder-2c1c</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;Some time ago, I made a joke encoding called Base8192. It looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input: What is base8192?
Base8192: 卶晡啂幩唲幢吗慥冃弹儣洀等
Base64: V2hhdCBpcyBiYXNlODE5Mj8=
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Base8192 utilises Chinese characters and uses fewer letters compared to Base64. In the example above, Base8192 uses only 13 characters, whereas Base64 needs 24 characters.&lt;/p&gt;

&lt;p&gt;If you're curious how it works, here is the GitHub link to the repo and README explains more details.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/karintomania/Base8192" rel="noopener noreferrer"&gt;https://github.com/karintomania/Base8192&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, I got an idea, implemented it and confirmed it works as expected.&lt;/p&gt;

&lt;p&gt;But now what? What if I wanted to encode something more than just user-input text?&lt;/p&gt;

&lt;h2&gt;
  
  
  Self-Hosting Dream
&lt;/h2&gt;

&lt;p&gt;I’ve heard that, in the world of making a compiler, compiling a compiler in your own compiler is a big milestone.&lt;/p&gt;

&lt;p&gt;This is called self-hosting. &lt;/p&gt;

&lt;p&gt;I decided to do something similar with my encoding: &lt;strong&gt;encoding an encoder with the encoder.&lt;/strong&gt;&lt;/p&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%2Fstlbuewl4gsbzh3hu0wa.jpg" 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%2Fstlbuewl4gsbzh3hu0wa.jpg" alt="matoryoshka" width="640" height="427"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;(Image:&lt;a href="https://unsplash.com/photos/red-blue-and-yellow-ceramic-figurine-PB80D_B4g7c" rel="noopener noreferrer"&gt;https://unsplash.com/photos/red-blue-and-yellow-ceramic-figurine-PB80D_B4g7c&lt;/a&gt;)&lt;/p&gt;

&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;My original implementation of Base8192 is written in JavaScript. I chose it because I wanted to make an interactive demo website. You can try out from the link below:&lt;br&gt;
&lt;a href="https://karintomania.github.io/Base8192/" rel="noopener noreferrer"&gt;https://karintomania.github.io/Base8192/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I want my new self-encoded encoder to be available in the website too, but it doesn't make sense to encode JavaScript code for the browser where you can run it directly.&lt;/p&gt;

&lt;p&gt;But, there is another runtime in browsers: WASM.&lt;/p&gt;

&lt;p&gt;To include a WASM binary in your code, there are a few ways to do it and encoding the binary and decoding it in JS is perfect for my case.&lt;/p&gt;
&lt;h2&gt;
  
  
  How to make WASM binary
&lt;/h2&gt;

&lt;p&gt;Up until I started this challenge, I didn’t really know what WASM is. Apparently various languages can be compiled to WASM (even &lt;a href="https://developer.fermyon.com/wasm-languages/javascript" rel="noopener noreferrer"&gt;JS&lt;/a&gt;!).&lt;/p&gt;

&lt;p&gt;My choice of language was zig. Simply because that is the language I've been playing with and its WASM support looks good.&lt;/p&gt;

&lt;p&gt;Another choice could have been Moonbit and it’s a quite interesting language. But at this point, I started to learn too many languages, so I resisted my urge to learn something shiny 😅&lt;/p&gt;

&lt;p&gt;So, the mental model of this project looks somewhat like the diagram below:&lt;/p&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%2Fiau1hfa2rkgktusjqena.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%2Fiau1hfa2rkgktusjqena.png" alt="project diagram" width="478" height="403"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Rewrite the encoder in zig
&lt;/h2&gt;

&lt;p&gt;Writing the same code in JavaScript and zig was a fun experience! These two languages are wildly different; JS is a high level, dynamically typed, scripting language with Garbage collector, whereas zig is a low level, statically typed, compiled language, with manual memory management.&lt;/p&gt;

&lt;p&gt;To my surprise, the amount of code is not too different. The core logic of the JS version (base8192.js) contains 288 lines and the zig version (base8192.zig) contains 258 lines (excluding tests in the same file).&lt;/p&gt;

&lt;p&gt;I expected zig code to have more lines given zig being a quite low level language! This is partially because my implementation in zig is a bit better as it’s my second iteration. But I think zig’s simple syntax helped to reduce the code volume.&lt;/p&gt;
&lt;h2&gt;
  
  
  Call WASM from JS
&lt;/h2&gt;

&lt;p&gt;Now, let’s call the encode/decode function defined in the WASM from JS!&lt;/p&gt;

&lt;p&gt;One thing you need to be careful about is that WASM functions can only return primitive types to JS. &lt;/p&gt;

&lt;p&gt;My encode function wants to return string, and decode function wants to return a struct. Neither string nor struct is supported. What do I do?&lt;/p&gt;

&lt;p&gt;To return a string, first we store the string as an array of 8-bit unsigned integers (u8) on WASM memory. Now, you somehow need to tell JS which address the string starts and the length of the string, so that the JS knows exactly where in the WASM memory to read.&lt;/p&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%2Fson36eeck8iznereraw8.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%2Fson36eeck8iznereraw8.png" alt="wasm memory layout image" width="650" height="188"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Since you can only return 1 value in function, this is a bit tricky (I had to remind myself a few times I can’t return an object like &lt;code&gt;{"address": xxx, "length": yyy}&lt;/code&gt; in WASM 😅).&lt;/p&gt;

&lt;p&gt;One straightforward solution is to create 2 functions, which returns the pointer and the length. For Base8192 encoding, the length of the encoded string is determined by the input’s size, so this is feasible.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight zig"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="n"&gt;getEncodeResultLen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inputLength&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="kt"&gt;u32&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c"&gt;// rest of the logic&lt;/span&gt;
    &lt;span class="c"&gt;// ...&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="n"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;input_ptr&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;usize&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="kt"&gt;u8&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c"&gt;// encoding logic&lt;/span&gt;
  &lt;span class="c"&gt;// ...&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c"&gt;// return pointer&lt;/span&gt;
 &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But this doesn’t work well for decoding as we only know the result of decoding after the decoding is done. This is because when Base8192 detects invalid sequences, it skips them until it reaches valid data again. Therefore, the length is unknown until the decoding finishes.&lt;/p&gt;

&lt;p&gt;What I did is to prefix the string with its length. It looks like below:&lt;/p&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%2Fy3ql4986v5bhejhu52jc.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%2Fy3ql4986v5bhejhu52jc.png" alt="wasm memory layout image" width="698" height="124"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The function returns pointer to the prefixed string. JS reads the first 4  bytes (32bits) and it is the length of the output. Now, JS can read the string, starting from the fifth byte and for the given length.&lt;/p&gt;

&lt;p&gt;For the decode function, I wanted to return the result string and the index of the detected errors (base 8192 is self synchronous, meaning it can detect errors and still can decode the rest of the input). It would be like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;result&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hello World!!&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;errors&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&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;I could do a similar approach, prefixing the result with length of result and errors array. But I got lazy 😅 and decided to just return JSON as string and prefix it with the length.&lt;/p&gt;

&lt;p&gt;This comes with some performance penalty on JS side to run &lt;code&gt;JSON.parse()&lt;/code&gt;, but I can take that trade-off for the ease of the implementation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Encode the encoder in the encoding
&lt;/h2&gt;

&lt;p&gt;Finally we can self-encode the encoder.&lt;/p&gt;

&lt;p&gt;The code below reasd the encoder file and store it in &lt;code&gt;sourceBinary&lt;/code&gt;. &lt;code&gt;sourceBinary&lt;/code&gt; is now used to create a WASM instance and the input of the &lt;code&gt;encode_w_binary&lt;/code&gt; function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;encode_self&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Read the binary file&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sourceBinary&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;readFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./zig-out/bin/base8192.WASM&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;typedArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Uint8Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sourceBinary&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// create WASM instance from the binary&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;WASM&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;WebAssembly&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;instantiate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;typedArray&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{}});&lt;/span&gt;

    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;WASMInstance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;WASM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;instance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;WASMMemory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;WASMInstance&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;memory&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// encode the binary with the WASM instance&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;encode_w_binary&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sourceBinary&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;WASMInstance&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;WASMMemory&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// write the JS string to encoder.js&lt;/span&gt;
    &lt;span class="nx"&gt;fs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;writeFileSync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./encoder.js&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;`export const encoded = "&lt;/span&gt;&lt;span class="p"&gt;${&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;";`&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;And here it is. The result is stored in &lt;code&gt;encoder.js&lt;/code&gt; like below (I managed to fit 10,000+ characters into one screenshot):&lt;/p&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%2Fk1h38gm14892xdm70u04.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%2Fk1h38gm14892xdm70u04.png" alt="result of self-encoding" width="800" height="424"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Beautiful 😊&lt;/p&gt;

&lt;p&gt;You can see the actual file on GitHub too: &lt;a href="https://raw.githubusercontent.com/karintomania/Base8192/refs/heads/main/encoder.js" rel="noopener noreferrer"&gt;https://raw.githubusercontent.com/karintomania/Base8192/refs/heads/main/encoder.js&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Benchmarking
&lt;/h2&gt;

&lt;p&gt;Although performance is not the reason I used WASM, I expected some improvement with the WASM version of the encoder. &lt;/p&gt;

&lt;p&gt;I created a 2 MB of csv file to measure how long it takes to encode it. &lt;/p&gt;

&lt;p&gt;Here is the result:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Speed (ms)&lt;/th&gt;
&lt;th&gt;Memory Usage (MB)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;JS&lt;/td&gt;
&lt;td&gt;220&lt;/td&gt;
&lt;td&gt;187&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WASM&lt;/td&gt;
&lt;td&gt;658&lt;/td&gt;
&lt;td&gt;142&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Memory usage is taken from &lt;code&gt;time&lt;/code&gt; command’s Maximum resident set size.&lt;/p&gt;

&lt;p&gt;Actually the JS version is faster! I ran the test multiple times but the result didn't change. I assume encoding is a kind of the task where JIT can do a great job. &lt;/p&gt;

&lt;p&gt;Memory usage is lower in the WASM version as expected.&lt;/p&gt;

&lt;h2&gt;
  
  
  Optimising the WASM
&lt;/h2&gt;

&lt;p&gt;I couldn’t accept the fact that my WASM is slower than JS 😅 and I remembered zig has multiple optimisation options.&lt;/p&gt;

&lt;p&gt;Zig has a build option for optimisation and by specifying the option, you can get a binary which is optimised for something.&lt;/p&gt;

&lt;p&gt;The standard options are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Debug (Provide better debug info)&lt;/li&gt;
&lt;li&gt;Fast (Optimised for speed)&lt;/li&gt;
&lt;li&gt;Small (Optimised for binary size)&lt;/li&gt;
&lt;li&gt;Safe (Optimised for memory safety)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The option I used was the small one. This is to make the binary small so that the demo site can be snappy to load. But for the benchmark, why not using the fastest option!&lt;/p&gt;

&lt;p&gt;After using the release-fast option, this is the result.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Speed (ms)&lt;/th&gt;
&lt;th&gt;Memory Usage (MB)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;JS&lt;/td&gt;
&lt;td&gt;220&lt;/td&gt;
&lt;td&gt;187&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WASM (small)&lt;/td&gt;
&lt;td&gt;658&lt;/td&gt;
&lt;td&gt;142&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;WASM (fast)&lt;/td&gt;
&lt;td&gt;183&lt;/td&gt;
&lt;td&gt;140&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This is like 350% faster (658 → 183ms) and WASM is now faster than JS! I’m really happy with this result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;If you are interested in Base8192, here is the interactive demo site, which runs the WASM binary:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://karintomania.github.io/Base8192/" rel="noopener noreferrer"&gt;https://karintomania.github.io/Base8192/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You might wonder the point of this article.&lt;/p&gt;

&lt;p&gt;Will Base8192 replace Base64? No.&lt;/p&gt;

&lt;p&gt;But after creating my own encoding and self-encoded the encoder, I learned more about encoding, WASM and a lot of low level stuff through zig!&lt;/p&gt;

&lt;p&gt;I hope you enjoy this article.&lt;/p&gt;

</description>
      <category>zig</category>
      <category>javascript</category>
      <category>webassembly</category>
    </item>
    <item>
      <title>Use variable variables of PHP to obfuscate code</title>
      <dc:creator>Hideaki</dc:creator>
      <pubDate>Tue, 25 Nov 2025 17:33:19 +0000</pubDate>
      <link>https://dev.to/hideaki_shimizu_75b25756f/use-variable-variables-of-php-to-obfuscate-code-2k4l</link>
      <guid>https://dev.to/hideaki_shimizu_75b25756f/use-variable-variables-of-php-to-obfuscate-code-2k4l</guid>
      <description>&lt;p&gt;I came across a weird PHP concept—variable variables.&lt;/p&gt;

&lt;p&gt;It works like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'foo'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$$a&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'bar'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="nv"&gt;$foo&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The variable &lt;code&gt;$foo&lt;/code&gt; in line 3 is not directly declared. Instead, &lt;code&gt;$$a&lt;/code&gt; in line 2 is interpreted as &lt;code&gt;$foo&lt;/code&gt; because PHP expands the value of &lt;code&gt;$a&lt;/code&gt; from line 1.&lt;/p&gt;

&lt;p&gt;I use this feature to obfuscate this Quine in PHP:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nv"&gt;$SS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'${"$$"}=" ";for($ss=33;$ss&amp;lt;127;$ss++)${chr($ss-1)}=chr($ss);
eval(preg_replace("/\s/","",substr($SS,132)));printf($_,$SS);#$$$$$$$$$
$_=$$$$$$$$$$$$$$$$$$$$$$$$$$$$${"$$"}.$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
{"$$"}.$$$$$$$$$$$$$$$$$$$$$$$$$      $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$${"$$"}.$$      $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$        $$$$$$${"$$"}.$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$                   $$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$${"$$"}.${"$                        $"}.$$$$${"$$"}.$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$                           $$$$$$$$$$$$$$$$$$$$$${
"$$"}.$$$$$$$$$$$$$$             $$              $$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$${"$$"             }.$$$            $$$$$$$$$$$$$$$$$$$$$$
$$$$${"$$"}.$$$$$$$             ${"$$             "}.$$$$$${"$$"}.$$$$$
$$$$$$$$$$$$$$$$$$$             $$$$$             $$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$              $$$$             $$$$$$$$$$${"$$"}.$$$
$$$$${"$$"}.$$$$$$$               $$$$$$$$$$$$$$$$$$$$${"$$"}.$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$                 $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$${"$$"}.$$$$$$$                    $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$                     $$$$$$$$$$$$$$$$$$$$$$$$$$$$
{"$$"}.$$$$$$$$$$$$$$$$$                      $$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$${"                      $$"}.$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$                     $$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$${"$$"}.$$$$$$$$${"$$"}                   .$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$                 $$$$$$$$$$$$$$$$$$$$
$$$$$$$$$${"$$"}.$$            $$$$$               $$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$             $$$$$              $$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$${"$$             "}.$$              $$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$             $$$$$              $$$$$$$$$$$$$$$$$$$$
${"$$"}.$$$$$$$$$$$             $$$$$              $$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$            $$$$$             $$$$$$$$$$$$$$$$$$$$$
$${"$$"}.$$$$$$$$$$$$                            $$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$                          $$$$$$$$$$$$$$$$$$$$$$$
$$$$$${"$$"}.$$$$$$$$$$$                      $$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$                $$$$$$$$$$$$$$$$$$$${"$$"}.$
$$$$$$$${"$$"}.$$$$${"$$"}.$$$$$      $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$$$$$$$${"$$"}.$$$$$$$$$$$      $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$$$${"$$"}.$$$$$$$$$$$$${"$$      "}.$$$$$$$$$$$$$$$$${"$$"}.$$$$$$
$$$$$$${"$$"}.$$$$$$$$$$$$$$$$$${"$$"}.$$$$$$$$$$$$$$$$$$$${"$$"}.$$$$$
$$$$$$$$$$$$$${"$$"}.$$$$$$$$$${"$$"}.$$$$$$$$$${"$$"}.$$$$$$$$$$$$$$$$
$$$$$$$$$$$${"$$"};#$$$$$$$$$$$$$$$$$$$$$$$$$'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="k"&gt;eval&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;substr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$SS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;132&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The key part of this code is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$SS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="err"&gt;'$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"$$"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$ss&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;33&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nv"&gt;$ss&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;127&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nv"&gt;$ss&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nb"&gt;chr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$ss&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;chr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$ss&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Firstly, PHP usually uses only alphanumeric characters and underscores for variable names. But if you use the &lt;code&gt;${}&lt;/code&gt; syntax, you can use pretty much any character for variable names, even the dollar sign itself.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;'$'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'dollar'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;'$'&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt; &lt;span class="c1"&gt;// dollar&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's look at the Quine code again, cleaned up a bit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"$$"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$ss&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;33&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nv"&gt;$ss&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;127&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nv"&gt;$ss&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nb"&gt;chr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$ss&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;chr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$ss&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;This code creates an ASCII ↔ variable variable conversion.&lt;/p&gt;

&lt;p&gt;The code starts with &lt;code&gt;${'$$'}=' ';&lt;/code&gt;. Note that space is ASCII code 32.&lt;/p&gt;

&lt;p&gt;The for-loop creates variable variables that follow this pattern:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;${[ASCII code N-1]} = '[ASCII code N]';&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;For example, when &lt;code&gt;N=33&lt;/code&gt;, this code is interpreted as follows:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;${' '}='!'&lt;/code&gt; (ASCII code 32 is space, 33 is &lt;code&gt;!&lt;/code&gt;). &lt;/p&gt;

&lt;p&gt;When &lt;code&gt;N=34&lt;/code&gt;, it will look like &lt;code&gt;${’!‘}=’"’&lt;/code&gt; and so on.&lt;/p&gt;

&lt;p&gt;Now, because &lt;code&gt;!&lt;/code&gt; is defined as &lt;code&gt;${' '}&lt;/code&gt; and space is defined by &lt;code&gt;${'$$'}&lt;/code&gt;, &lt;code&gt;!&lt;/code&gt; can also be represented as &lt;code&gt;$${'$$'}&lt;/code&gt; using variable variables. Likewise, &lt;code&gt;"&lt;/code&gt; is &lt;code&gt;$$${'$$'}&lt;/code&gt;, and so on.&lt;/p&gt;

&lt;p&gt;After the for-loop is finished, all ASCII characters can be written as &lt;code&gt;[$ for (ASCII code - 31) times]{'$$'}&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;Here are some examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;'$$'&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt; &lt;span class="c1"&gt;// space: ASCII 32&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="err"&gt;$$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;'$$'&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt; &lt;span class="c1"&gt;// !: ASCII 33&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="err"&gt;$$$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;'$$'&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt; &lt;span class="c1"&gt;// #: ASCII 34&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="err"&gt;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"$$"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="c1"&gt;// A: ASCII 65&lt;/span&gt;
&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="err"&gt;$$$$$$$$$$$$$$$$$$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"$$"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="c1"&gt;// 1: ASCII 49&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Using this, a "Hello World" program looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"$$"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$ss&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;33&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nv"&gt;$ss&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mi"&gt;127&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nv"&gt;$ss&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
    &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nb"&gt;chr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$ss&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;chr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$ss&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;print&lt;/span&gt; &lt;span class="err"&gt;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"$$"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="c1"&gt;// H&lt;/span&gt;
&lt;span class="err"&gt;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"$$"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="c1"&gt;// e&lt;/span&gt;
&lt;span class="err"&gt;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"$$"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="c1"&gt;// l&lt;/span&gt;
&lt;span class="err"&gt;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"$$"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="c1"&gt;// l&lt;/span&gt;
&lt;span class="err"&gt;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"$$"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="c1"&gt;// o&lt;/span&gt;
&lt;span class="err"&gt;$$$$$$$$$$$$$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"$$"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="c1"&gt;// ,&lt;/span&gt;
&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"$$"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="c1"&gt;// ' '&lt;/span&gt;
&lt;span class="err"&gt;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"$$"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="c1"&gt;// W&lt;/span&gt;
&lt;span class="err"&gt;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"$$"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="c1"&gt;// o&lt;/span&gt;
&lt;span class="err"&gt;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"$$"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="c1"&gt;// r&lt;/span&gt;
&lt;span class="err"&gt;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"$$"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="c1"&gt;// l&lt;/span&gt;
&lt;span class="err"&gt;$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"$$"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="c1"&gt;// d&lt;/span&gt;
&lt;span class="err"&gt;$$&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"$$"&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt; &lt;span class="c1"&gt;// !&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that you can't use single-letter variables in this code, such as &lt;code&gt;$i&lt;/code&gt; for the counter. All single-letter variables are defined in the for loop (e.g., &lt;code&gt;$i&lt;/code&gt; is defined as the string &lt;code&gt;j&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Now, all that's left is to write a Quine using this technique, which gives us the code shown at the top of the article.&lt;/p&gt;

&lt;p&gt;I hope you enjoyed this article. Happy coding!&lt;/p&gt;

</description>
      <category>php</category>
      <category>programming</category>
      <category>security</category>
    </item>
    <item>
      <title>How to Create Quine and Quine Relay Code</title>
      <dc:creator>Hideaki</dc:creator>
      <pubDate>Sun, 19 Oct 2025 21:01:09 +0000</pubDate>
      <link>https://dev.to/hideaki_shimizu_75b25756f/how-to-create-quine-and-quine-relay-code-5e0b</link>
      <guid>https://dev.to/hideaki_shimizu_75b25756f/how-to-create-quine-and-quine-relay-code-5e0b</guid>
      <description>&lt;p&gt;The first time I read the Wikipedia article about quines, I was trying to understand it but couldn't have figured it out. Looking back, I think it was because I was programming in Java at that point, and Java isn't the best language for writing quines.&lt;/p&gt;

&lt;p&gt;Recently, I revisited the concept and it clicked this time. I can now understand how they work. In this article, I'll share everything I've learnt as simple as possible.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; I used AI to proofread my article, but I wrote all of the code in this article.&lt;/p&gt;

&lt;h2&gt;
  
  
  Anatomy of a Quine
&lt;/h2&gt;

&lt;p&gt;In this article, I use Python because of its concise syntax and popularity. Once you understand the principles here, you can write quines in the language of your choice.&lt;/p&gt;

&lt;p&gt;Here is the quine in Python, which we will create in this article:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s=%c%s%c; print(s%%(39,s,39)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;39&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;39&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can run this code in your browser using an online Python interpreter like &lt;a href="https://pythononline.net/" rel="noopener noreferrer"&gt;https://pythononline.net/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Don't worry if you don't understand what's going on yet. I'll explain it step by step.&lt;/p&gt;

&lt;h3&gt;
  
  
  First Step: Data and Print
&lt;/h3&gt;

&lt;p&gt;I want to build a quine incrementally, starting from the basics.&lt;/p&gt;

&lt;p&gt;Here is the first version of the code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# version 1
&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;print(s)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# output
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code simply prints the string &lt;code&gt;print(s)&lt;/code&gt;, but it already contains the two essential parts of a quine:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Data definition&lt;/strong&gt; — storing the code as data&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data printing&lt;/strong&gt; — outputting that data
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;print(s)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="c1"&gt;# data definition
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;     &lt;span class="c1"&gt;# printing data
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Paradox of Updating the Data Definition
&lt;/h3&gt;

&lt;p&gt;Version 1 only prints the printing part. To turn this into a proper quine, we need to print the data definition as well. So I edited the code like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# version 2
&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;s=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;print(s)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;
print(s)&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;  &lt;span class="c1"&gt;# define data including data definition
&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;     &lt;span class="c1"&gt;# print data
&lt;/span&gt;
&lt;span class="c1"&gt;# output of version 2
&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;print(s)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(I used Python's &lt;code&gt;"""&lt;/code&gt; syntax to include a newline in the string.)&lt;/p&gt;

&lt;p&gt;Now it prints the previous code. But here's the problem: because we changed the data definition, the original code is now different! This is the paradox that makes quines tricky. Every time you change the data to print the code, the code itself changes.&lt;/p&gt;

&lt;h3&gt;
  
  
  Include the Data in the Data Itself
&lt;/h3&gt;

&lt;p&gt;If you look closely at version 2, you'll notice there are actually two data definitions: the actual definition and the one inside the double quotes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# version 2
&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;s=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;print(s)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;
print(s)&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Its result
&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;print(s)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;↓ Outside definition:
s="""s="print(s)"
     ↑ Inside definition
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The trick to making a quine work is to use the data from the outside definition to fill in the inside definition.&lt;/p&gt;

&lt;p&gt;More specifically, in Python, you can use the &lt;code&gt;%&lt;/code&gt; operator inside &lt;code&gt;print()&lt;/code&gt; to insert values into strings:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;I like %s!&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Python&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;# this prints "I like Python!"
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If I apply this to our code, it would look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# version 3
&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;s=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;%s&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;
print(s)&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# Replace %s with the value of s
&lt;/span&gt;
&lt;span class="c1"&gt;# output of version 3
&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;s=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;
print(s)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output looks quite similar to the original code!&lt;/p&gt;

&lt;h3&gt;
  
  
  Tidy the Code
&lt;/h3&gt;

&lt;p&gt;You're almost there! In the last section, you handled the core concept of quines. What's left is the somewhat tedious part: tidying up the code by dealing with special characters.&lt;/p&gt;

&lt;p&gt;Let's look at version 3 again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# version 3
&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;s=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;%s&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;
print(s)&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this point, we need to handle special characters that can't be printed directly:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Newlines&lt;/li&gt;
&lt;li&gt;Quotes&lt;/li&gt;
&lt;li&gt;Percent symbols&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In general, I prefer to make quines one-liners to keep the code simpler. If the code includes a newline, the data needs to be quoted specially in most languages (like the triple quotes in Python).&lt;/p&gt;

&lt;p&gt;So I removed the newline and used a semicolon instead. Since we no longer need triple quotes, I replaced them with single quotes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# version 4
&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;; print(s)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But this code causes a syntax error because you can't use a single quote inside single quotes.&lt;br&gt;
In normal programming, you could escape the quote, but in a quine, that doesn't work because the output would have a syntax error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# version 4.1
&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s=&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt;%s&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt;; print(s)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# this is correct
&lt;/span&gt;
&lt;span class="c1"&gt;# output
&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;; print(s)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# syntax error!
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One way to handle this is to use &lt;code&gt;%c&lt;/code&gt; in the format string, just like we used &lt;code&gt;%s&lt;/code&gt; to expand the data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# version 4.2
&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s=%c%s%c; print(s)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;39&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;39&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="c1"&gt;# output
&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s=%c%s%c; print(s)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The magic number 39 is the ASCII code for a single quote.&lt;/p&gt;

&lt;p&gt;What's left is the printing part inside the data: &lt;code&gt;print(s%(39,s,39))&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The only tricky bit here is that you need to escape the percent sign in the data. Luckily, you can just use double percent (&lt;code&gt;%%&lt;/code&gt;) to escape it.&lt;/p&gt;

&lt;p&gt;Here's the final version and it's a proper quine!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# version 5
&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s=%c%s%c; print(s%%(39,s,39))&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;39&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;39&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="c1"&gt;# output
&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s=%c%s%c; print(s%%(39,s,39))&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;39&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;39&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Quine Relay
&lt;/h2&gt;

&lt;p&gt;Now that we know how to write a quine, let's take it to the next level!&lt;/p&gt;

&lt;p&gt;A quine relay is a program that prints code in a different language, which prints code in yet another language, and so on until it eventually prints the original code again.&lt;/p&gt;

&lt;p&gt;I'll create a quine relay between Python and PHP, walking through the process step by step.&lt;/p&gt;

&lt;h3&gt;
  
  
  Python Printing PHP
&lt;/h3&gt;

&lt;p&gt;Here's version 1:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# version 1
&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;here is some python code&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?php print(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;%s&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;);&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# result
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;here is some python code;&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The printed result is actually valid PHP code. The idea here is that instead of printing &lt;code&gt;"here is some python code"&lt;/code&gt;, we want the PHP code to print the original Python code.&lt;/p&gt;

&lt;p&gt;Let's replace the content of variable &lt;code&gt;s&lt;/code&gt; with a more realistic value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# version 2
&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s=&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt;%s&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt;;print(&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?php print(%s);&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt; %% s)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?php print(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;%s&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;);&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# result PHP
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;s=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;%s&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;;print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?php print(%s);&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; %% s)&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;# result of result PHP
&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;%s&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?php print(%s);&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="o"&gt;%%&lt;/span&gt; &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hopefully you can see where we're going. If you look at the final result, you'll notice we only need to replace the first &lt;code&gt;%s&lt;/code&gt; with the value of &lt;code&gt;s&lt;/code&gt; from the original code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add Self-Replicating Code
&lt;/h3&gt;

&lt;p&gt;So I added the replacement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Version 3
&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s=&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt;%s&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt;;print(&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?php print(%%s);&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt; %% s)&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?php print(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;%s&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;);&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="c1"&gt;# result PHP
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;s=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;%s&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;;print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?php print(%%s);&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; %% (s%%s))&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;;print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?php print(%s);&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; % (s%s))&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This part is where the magic happens.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?php print(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;%s&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;);&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;(s%s)&lt;/code&gt; is expanding &lt;code&gt;s&lt;/code&gt; inside &lt;code&gt;s&lt;/code&gt; itself, and the result gets added to the PHP code output.&lt;/p&gt;

&lt;p&gt;The string that PHP is trying to print is quite close to the original Python code, but the PHP code itself is no longer valid. Let's fix the escaping.&lt;/p&gt;

&lt;p&gt;After some trial and error, I managed to make the escaping work:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Version 4
&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;s=%r;print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?php print(%%r);&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; %% (s%%s))&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?php print(%r);&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="c1"&gt;# Result PHP
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;?&lt;/span&gt;&lt;span class="n"&gt;php&lt;/span&gt; &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;s=%r;print(&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?php print(%%r);&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt; %% (s%%s))&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;;print(&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?php print(%r);&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt; % (s%s))&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;# Result Python of Result PHP
&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;s=%r;print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?php print(%%r);&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; %% (s%%s))&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?php print(%r);&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The trick here is Python's &lt;code&gt;%r&lt;/code&gt; formatter. This is similar to &lt;code&gt;%s&lt;/code&gt;, but it prints strings as valid Python code, automatically handling quote escaping for you.&lt;/p&gt;

&lt;h3&gt;
  
  
  Obfuscate the Code
&lt;/h3&gt;

&lt;p&gt;You'll notice that many quine examples online are somewhat obfuscated, so let's make our quine relay harder to read. This is a rare opportunity—in your day job, you don't normally get to obfuscate your code!&lt;/p&gt;

&lt;p&gt;First, I'll use &lt;code&gt;_&lt;/code&gt; instead of &lt;code&gt;s&lt;/code&gt; as the variable name to make the code look more eccentric. We can also remove all unnecessary whitespace.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Version 5
&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;_=%r;print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?php print(%%r);&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;%%(_%%_))&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?php print(%r);&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In PHP, you can also use a shorthand syntax: instead of &lt;code&gt;&amp;lt;?php print("something");&lt;/code&gt;, you can write &lt;code&gt;&amp;lt;?="something"?&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here's my final version of the quine relay:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Version 5
&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;_=%r;print(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?=%%r?&amp;gt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;%%(_%%_))&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?=%r?&amp;gt;&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="c1"&gt;# Result PHP
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="err"&gt;?&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;_=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;_=%r;print(&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?=%%r?&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt;%%(_%%_))&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;;print(&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;?=%r?&amp;gt;&lt;/span&gt;&lt;span class="se"&gt;\'&lt;/span&gt;&lt;span class="s"&gt;%(_%_))&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="err"&gt;?&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Quines available online are often optimised for strangeness most of the time (which is cool, but not good for explanation purposes 😅).&lt;br&gt;
Hopefully this article helped you to understand this strange and beautiful concept in a readable code.&lt;/p&gt;

&lt;p&gt;To be fair, once I understood the concept, what I enjoyed the most was obfuscating the code. What I learned from this experience is that reading obfuscated code is much harder than writing obfuscated code. So, I might write another article about explaining tricky code!&lt;/p&gt;

&lt;p&gt;Thanks for reading 😆&lt;/p&gt;

&lt;h2&gt;
  
  
  Reference
&lt;/h2&gt;

&lt;p&gt;If you are interested in writing your own quines, these articles are useful and inspiring.&lt;br&gt;
&lt;a href="https://en.wikipedia.org/wiki/Quine_(computing)" rel="noopener noreferrer"&gt;Wikipedia quine&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/kirjavascript/quine-howto" rel="noopener noreferrer"&gt;Quine How To&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/mame/quine-relay" rel="noopener noreferrer"&gt;Quine relay with 128 languages&lt;/a&gt;&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>python</category>
      <category>tutorial</category>
      <category>programming</category>
    </item>
    <item>
      <title>How to Handle HTTP Responses with the Stream+JSON Content Type Using PHP Generators</title>
      <dc:creator>Hideaki</dc:creator>
      <pubDate>Tue, 06 May 2025 16:04:53 +0000</pubDate>
      <link>https://dev.to/hideaki_shimizu_75b25756f/how-to-handle-http-responses-with-the-streamjson-content-type-using-php-generators-17ld</link>
      <guid>https://dev.to/hideaki_shimizu_75b25756f/how-to-handle-http-responses-with-the-streamjson-content-type-using-php-generators-17ld</guid>
      <description>&lt;p&gt;In this article, I'll discuss: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What Content-Type: stream+json is&lt;/li&gt;
&lt;li&gt;How to handle stream+json responses with PHP&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The sample code is fully open source and available here:&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://github.com/karintomania/php-stream-example" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you have Docker Compose installed on your machine, you can run the code without installing anything extra.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is Content-Type: stream+json?
&lt;/h2&gt;

&lt;p&gt;Before we dive into coding, let's quickly explore why &lt;code&gt;stream+json&lt;/code&gt; exists. Often, you need to send large arrays of JSON via APIs. You could send this large array from the server all at once, but when PHP receives it, PHP loads everything into memory.&lt;/p&gt;

&lt;p&gt;While this method works, it can cause issues such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;High memory consumption&lt;/li&gt;
&lt;li&gt;Risk of timeout ⏳&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;How to solve these problems?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;💡Solution: Content-Type: stream+json&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
To tackle these issues, the &lt;code&gt;stream+json&lt;/code&gt; content type is used. For this content type, the server sends a "stream" of data, which consists of lines of JSON in this case.&lt;br&gt;&lt;br&gt;
See the GIF below, which shows how a server can send JSONs on a stream with Content-Type: stream+json.  &lt;/p&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%2Fz38fvz85p55evhdf6zh4.gif" 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%2Fz38fvz85p55evhdf6zh4.gif" alt="Image description" width="480" height="853"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, the server is sending JSON line-by-line.&lt;br&gt;&lt;br&gt;
This format is called JSON Lines (or JSONL for short), which is a newline-separated JSON. JSONL allows data to be processed line-by-line, making it easier to handle large JSON objects efficiently. &lt;br&gt;
Because each line is a valid JSON, PHP can start processing the object as it receives it, without waiting for the whole response.&lt;/p&gt;

&lt;p&gt;In summary, using Content-Type: stream+json allows the program to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start processing immediately without waiting for the entire response ⏩&lt;/li&gt;
&lt;li&gt;Use less memory by processing JSON one by one, instead of dealing with a massive array of JSON&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Receiving the Stream+JSON Response as a Stream with Guzzle
&lt;/h2&gt;

&lt;p&gt;Now, let's talk about how to handle a &lt;code&gt;stream+json&lt;/code&gt; response.&lt;/p&gt;

&lt;p&gt;Before diving into the implementation, it's important to clarify a common point of confusion:&lt;br&gt;&lt;br&gt;
PHP has built-in functions called Streams. This stream refers to a way to manage resources like files or HTTP in a unified manner. However, the "stream" discussed in this article refers to HTTP responses using the &lt;code&gt;stream+json&lt;/code&gt; content type.&lt;br&gt;&lt;br&gt;
More about PHP's built-in streams: &lt;a href="https://www.php.net/manual/en/book.stream.php" rel="noopener noreferrer"&gt;PHP Streams Documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Fortunately, the Guzzle library has a handy "stream" option to get the response as a stream. All you need to do is set this &lt;code&gt;'stream'&lt;/code&gt; option to &lt;code&gt;true&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;GuzzleHttp\Client&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$client&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Client&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="c1"&gt;// Enable the stream option&lt;/span&gt;
&lt;span class="nv"&gt;$response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$client&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'http://localhost'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'stream'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="c1"&gt;// getBody() retrieves the response as a stream&lt;/span&gt;
&lt;span class="nv"&gt;$stream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$response&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getBody&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you run the code above, you will have the response as a stream, more specifically as a &lt;code&gt;StreamInterface&lt;/code&gt;. &lt;code&gt;StreamInterface&lt;/code&gt; is defined by PSR-7 as an interface for data streams. If you want to know more about this interface, see the link below for details:&lt;br&gt;&lt;br&gt;
&lt;a href="https://github.com/php-fig/http-message/blob/master/src/StreamInterface.php" rel="noopener noreferrer"&gt;StreamInterface Documentation&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One of the important methods of "StreamInterface" is the &lt;code&gt;read(int $length)&lt;/code&gt; method, which allows you to retrieve content of the specified length. We will see how to handle the JSON stream line by line using this method in the next section.&lt;/p&gt;

&lt;p&gt;Note that if you don't set the stream option, the &lt;code&gt;getBody()&lt;/code&gt; function will wait for the whole response and return it as a string.&lt;/p&gt;
&lt;h2&gt;
  
  
  Handling the Stream with PHP Generators
&lt;/h2&gt;

&lt;p&gt;Since the stream sends JSON line-by-line, using a Generator is an efficient approach, as it allows the consumer to process each object one by one.&lt;/p&gt;

&lt;p&gt;Here's a class that demonstrates how to process the stream and return JSON-decoded objects using a Generator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;StreamTest&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;Psr\Http\Message\StreamInterface&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kn"&gt;use&lt;/span&gt; &lt;span class="nc"&gt;\Generator&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;StreamScanner&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;const&lt;/span&gt; &lt;span class="no"&gt;CHUNK_SIZE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;8192&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="cd"&gt;/**
    * @return Generator&amp;lt;object&amp;gt;
    *
    * Read each line from the stream and return it as an object.
    * Each line will be a JSON object.
    */&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;__invoke&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;StreamInterface&lt;/span&gt; &lt;span class="nv"&gt;$stream&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;Generator&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;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;nextLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$stream&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nv"&gt;$line&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nb"&gt;json_decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$line&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="cd"&gt;/**
     * @return Generator&amp;lt;string&amp;gt;
     *
     * Read each line from the stream.
     */&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;nextLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;StreamInterface&lt;/span&gt; &lt;span class="nv"&gt;$stream&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;Generator&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$buffer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// Read chunks until EOF&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;$stream&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;eof&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$buffer&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$stream&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;CHUNK_SIZE&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

            &lt;span class="c1"&gt;// If buffer has a newline, yield a JSON line&lt;/span&gt;
            &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nv"&gt;$pos&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;strpos&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$buffer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&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="c1"&gt;// Get the complete JSON&lt;/span&gt;
                &lt;span class="nv"&gt;$line&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;substr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$buffer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$pos&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="nv"&gt;$buffer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;substr&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$buffer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$pos&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nv"&gt;$line&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="c1"&gt;// Process any remaining buffer&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;$buffer&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;yield&lt;/span&gt; &lt;span class="nv"&gt;$buffer&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's break down this code a bit.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;__invoke&lt;/code&gt; Method
&lt;/h4&gt;

&lt;p&gt;This method returns a generator of JSON-decoded objects. It retrieves each line from the &lt;code&gt;nextLine&lt;/code&gt; method and applies &lt;code&gt;json_decode()&lt;/code&gt; to convert the JSON string into an object.&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;code&gt;nextLine&lt;/code&gt; Method
&lt;/h4&gt;

&lt;p&gt;This method processes the stream in chunks and identifies complete lines by searching for newline characters. It continues reading until the end of the file is reached, ensuring that all lines are processed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Note on &lt;code&gt;GuzzleHttp\Psr7\Utils::readLine&lt;/code&gt; Method
&lt;/h3&gt;

&lt;p&gt;Guzzle offers &lt;code&gt;Utils::readLine()&lt;/code&gt; function, which works like my StreamScanner.&lt;br&gt;&lt;br&gt;
&lt;a href="https://github.com/guzzle/psr7/blob/2.7/src/Utils.php#L234" rel="noopener noreferrer"&gt;https://github.com/guzzle/psr7/blob/2.7/src/Utils.php#L234&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This function, as the name suggests, reads one line from the stream. The differences from the StreamScanner in this article are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It returns a string, instead of a Generator.&lt;/li&gt;
&lt;li&gt;The implementation reads the stream one character at a time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because it reads the stream one character at a time instead of reading chunks, this function can be slow.&lt;/p&gt;

&lt;p&gt;I processed a JSONL file with 100K lines using both implementations and the result is:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;StreamScanner: 0.049s
&lt;/li&gt;
&lt;li&gt;Utils::readLine: 0.416s&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;Utils::readLine&lt;/code&gt; is very useful when the file is not large or the speed is not your concern (like batch jobs, for example). Also, if you can't use Generators, you should use &lt;code&gt;Utils::readLine&lt;/code&gt;.&lt;/p&gt;
&lt;h2&gt;
  
  
  Testing the Implementation
&lt;/h2&gt;

&lt;p&gt;Let's talk about testing. Mocking the stream for testing purposes is actually not too hard.&lt;/p&gt;

&lt;p&gt;For testing purposes, Guzzle offers a convenient function called &lt;code&gt;Utils::streamFor()&lt;/code&gt;, which converts a resource into a &lt;code&gt;StreamInterface&lt;/code&gt;. This is particularly useful for testing your stream handling logic.&lt;/p&gt;

&lt;p&gt;For example, if you have a JSON file that resembles the actual payload of the response, you can write something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$f&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;fopen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;__DIR__&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'/data.json'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'r'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$stream&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Utils&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;streamFor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$f&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you have the stream. If you are using Guzzle to make the request, you can mock the Guzzle client to return this stream. It's another benefit of using PSR-defined interfaces, as it protects the code from implementation details.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;stream+json&lt;/code&gt; content type, utilizing the JSONL format, is a powerful solution for managing extensive HTTP responses. By employing streams and generators, you can create memory-efficient code capable of handling large data sets with ease.&lt;/p&gt;

&lt;p&gt;All of the sample code and more examples are available in my GitHub repo:&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://github.com/karintomania/php-stream-example" rel="noopener noreferrer"&gt;GitHub Repository&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope this article helps you. Happy coding! 😊&lt;/p&gt;

</description>
      <category>php</category>
    </item>
    <item>
      <title>My Experience of Letting AI Handle a Whole PR Without Touching the Code</title>
      <dc:creator>Hideaki</dc:creator>
      <pubDate>Tue, 06 May 2025 08:53:08 +0000</pubDate>
      <link>https://dev.to/hideaki_shimizu_75b25756f/my-experience-of-letting-ai-handle-a-whole-pr-without-touching-the-code-n96</link>
      <guid>https://dev.to/hideaki_shimizu_75b25756f/my-experience-of-letting-ai-handle-a-whole-pr-without-touching-the-code-n96</guid>
      <description>&lt;p&gt;Today, I want to share my experience using Cline (&lt;a href="https://github.com/cline/cline" rel="noopener noreferrer"&gt;https://github.com/cline/cline&lt;/a&gt;) to manage an entire pull request (PR) without touching the code myself.&lt;/p&gt;

&lt;h1&gt;
  
  
  Rules
&lt;/h1&gt;

&lt;p&gt;I set the following rules for myself to complete the PR:&lt;br&gt;
Only let the AI write the code. Editing the code generated by the AI was not allowed.&lt;br&gt;
Use Cline as much as possible to let the AI handle everything. If it didn't work, use Copilot Chat. As a last resort, copy and paste from the web version of ChatGPT.&lt;br&gt;
Running commands like linting by myself was allowed. (It's just faster to run the commands myself than telling AI to run the exact command.)&lt;/p&gt;

&lt;p&gt;The task I chose for the AI was a refactoring task to unify the implementation of mocking across the codebase, which varied by developer.&lt;/p&gt;
&lt;h1&gt;
  
  
  Environment
&lt;/h1&gt;

&lt;p&gt;I used the vanilla Cline VS Code extension.&lt;br&gt;
I tried the following two models:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;vscode-lm:copilot/gpt-4&lt;/li&gt;
&lt;li&gt;vscode-lm:copilot/gpt-4o&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The codebase was an average Laravel application.&lt;/p&gt;
&lt;h1&gt;
  
  
  Positives
&lt;/h1&gt;
&lt;h2&gt;
  
  
  The PR was completed without touching the code.
&lt;/h2&gt;

&lt;p&gt;The task was completed entirely through prompts. I wasn't sure if it was possible, but Cline made it. This was a different experience from Copilot, where once the prompt was written, the AI handled everything.&lt;/p&gt;
&lt;h2&gt;
  
  
  The AI can handle tasks beyond just writing code
&lt;/h2&gt;

&lt;p&gt;Cline was able to handle various tasks beyond just reading and writing code.&lt;/p&gt;

&lt;p&gt;Here are some tasks I asked it to do:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use ripgrep to find refactoring points&lt;/li&gt;
&lt;li&gt;Run tests to verify the correctness of the code and fix errors if any&lt;/li&gt;
&lt;li&gt;Format the code to a consistent style&lt;/li&gt;
&lt;li&gt;Generate Git commits, comments, and PR descriptions from git diff&lt;/li&gt;
&lt;li&gt;Write blog posts from notes I took during experiments (like this article!)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These techniques are useful and something I plan to use in my day-to-day tasks.&lt;/p&gt;
&lt;h1&gt;
  
  
  Negatives
&lt;/h1&gt;

&lt;p&gt;The biggest negative point was that honestly, it felt faster and easier to write the code myself.&lt;/p&gt;
&lt;h2&gt;
  
  
  AI is not that smart yet
&lt;/h2&gt;

&lt;p&gt;The task was relatively simple, unifying the implementation of mocks, but the AI struggled to understand the intent of the prompts and the existing code. It often made unrelated changes or misunderstood what it meant to do.&lt;/p&gt;

&lt;p&gt;There were also many instances where it got stuck in an infinite loop, repeatedly fixing the same error.&lt;br&gt;
Additionally, I had to include sample code in the prompt to show the correct way to write mocks. This might be because many PHP codes are written without tests, so AI doesn't have enough training data.&lt;/p&gt;
&lt;h2&gt;
  
  
  Prompt engineering is challenging
&lt;/h2&gt;

&lt;p&gt;Related to the above, prompt engineering is necessary to correctly convey what you want the AI to perform.&lt;br&gt;
Here is the prompt I used, which is very long and specific.&lt;br&gt;
It took trial and error to reach the final version.&lt;br&gt;
I believe I could have finished the task myself in the time it took to write this prompt.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Prompt
In the tests/ folder, I want to unify how mocking is implemented.

# Rules
- There are instances of using mock(), Mockery::mock(), or $this-&amp;gt;mock().
- Don't change anything apart from mock(), Mockery::mock(), or $this-&amp;gt;mock() even if you find an error or improvements.

## mock()
- Keep mock() if it only has a first argument.
- If it has an anonymous function to make assertions for the second argument, remove the second argument and add lines to do the equivalent.
- The mock should look like below without comments:
$mock = mock(UserRepository::class); // create mock. Only use the first argument

$mock-&amp;gt;shouldReceive('function name') // insert function name to mock
-&amp;gt;with('expected input') // insert expected args if applicable
-&amp;gt;andReturn('expected output') // insert expected output if applicable
-&amp;gt;once();

## Mockery::mock()
- Change it to use mock() and do the same for mock()

## $this-&amp;gt;mock()
- Change it to use mock()
- Add app()-&amp;gt;instance()/app()-&amp;gt;bind() to bind the mock to the mocked class
- Prefer to use app()-&amp;gt;instance(). But when instantiation needs to pass arguments, use app()-&amp;gt;bind() and pass an anonymous function for the second argument.

# Contexts
- This is a Laravel app and uses Pest as a testing library.
- It uses Mockery for mocking.
- You can verify if the test passes or not by running `make test-unit &amp;amp;&amp;amp; make test-feature`
- You can check the use of $this-&amp;gt;mock or Mockery::mock by running these commands:
+ rg '\$this-&amp;gt;mock' tests/
+ rg Mockery::mock tests/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Code generation is quite slow
&lt;/h2&gt;

&lt;p&gt;When using GPT-4, it took quite a while for the actual code diff to be presented. GPT-4o was faster than GPT-4, but it still sometimes stopped generating code.&lt;/p&gt;

&lt;p&gt;Also, when the file itself was large, even a single line change would make the AI generate the entire file. Because of this, in my machine, editing files with 500+ lines failed.&lt;br&gt;
Therefore, when changing only part of a large file, it was sometimes faster to use Copilot Chat, which can show only the diff.&lt;br&gt;
These points are still frustrating compared to normal coding, but I believe they will be resolved as models improve in the future.&lt;/p&gt;
&lt;h1&gt;
  
  
  Bonus
&lt;/h1&gt;

&lt;p&gt;Here are some useful prompts I found.&lt;/p&gt;
&lt;h2&gt;
  
  
  Create a commit
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Read the staging changes by running `git --no-pager diff --staged` and commit it with an appropriate message.
Make the first line concise and add details after a newline if necessary
When letting Cline read the git command results, use the ` - -no-pager` option to avoid having to scroll the command result manually.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Create PR details
&lt;/h2&gt;

&lt;p&gt;When creating a PR on GitHub, there is usually a project template, and this prompt can automatically fill it out.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Compare the diff between the current branch and master branch and fill this template for PR.

# Title
Title for this PR
# Motivation
The motivation of this PR
# Description
Details of the PR.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Overall, I found it more useful than I expected.&lt;br&gt;
Although there are still some frustrating points, I believe that with faster and smarter models in the future, AI coding might become mainstream.&lt;br&gt;
Happy coding (or prompting)!&lt;/p&gt;

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