<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/rss-style.xsl" type="text/xsl"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	    xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	     xmlns:dc="http://purl.org/dc/elements/1.1/"
	   xmlns:atom="http://www.w3.org/2005/Atom"
	     xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	  xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>🧑🏾‍❤️‍💋‍🧑🏻 &#8211; Terence Eden’s Blog</title>
	<atom:link href="https://shkspr.mobi/blog/tag/%f0%9f%a7%91%f0%9f%8f%be%e2%9d%a4%ef%b8%8f%f0%9f%92%8b%f0%9f%a7%91%f0%9f%8f%bb/feed/" rel="self" type="application/rss+xml" />
	<link>https://shkspr.mobi/blog</link>
	<description>Regular nonsense about tech and its effects 🙃</description>
	<lastBuildDate>Wed, 12 Feb 2025 10:03:41 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://shkspr.mobi/blog/wp-content/uploads/2023/07/cropped-avatar-32x32.jpeg</url>
	<title>🧑🏾‍❤️‍💋‍🧑🏻 &#8211; Terence Eden’s Blog</title>
	<link>https://shkspr.mobi/blog</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title><![CDATA[Where you can (and can't) use Emoji in PHP]]></title>
		<link>https://shkspr.mobi/blog/2024/04/where-you-can-and-cant-use-emoji-in-php/</link>
					<comments>https://shkspr.mobi/blog/2024/04/where-you-can-and-cant-use-emoji-in-php/#comments</comments>
				<dc:creator><![CDATA[@edent]]></dc:creator>
		<pubDate>Sat, 20 Apr 2024 11:34:04 +0000</pubDate>
				<category><![CDATA[/etc/]]></category>
		<category><![CDATA[emoji]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[unicode]]></category>
		<category><![CDATA[🧑🏾‍❤️‍💋‍🧑🏻]]></category>
		<guid isPermaLink="false">https://shkspr.mobi/blog/?p=50268</guid>

					<description><![CDATA[I was noodling around in PHP the other day and discovered that this works:  &#60;?php $🍞 = &#34;bread&#34;; echo &#34;Some delicious &#34; . $🍞;   I mean, there&#039;s no reason why it shouldn&#039;t work. An emoji is just a Unicode character (OK, not just a character - but we&#039;ll get on to that), so it should be fine to use anywhere.  Emoji work perfectly well as function names:  function 😺🐶() {    echo &#34;catdog!&#34;; } 😺🐶();   De…]]></description>
										<content:encoded><![CDATA[<p>I was noodling around in PHP the other day and discovered that this works:</p>

<pre><code class="language-php">&lt;?php
$🍞 = "bread";
echo "Some delicious " . $🍞;
</code></pre>

<p>I mean, there's no reason why it <em>shouldn't</em> work. An emoji is just a Unicode character (OK, not just <em>a</em> character - but we'll get on to that), so it should be fine to use anywhere.</p>

<p>Emoji work perfectly well as function names:</p>

<pre><code class="language-php">function 😺🐶() {
   echo "catdog!";
}
😺🐶();
</code></pre>

<p>Definitions:</p>

<pre><code class="language-php">define( "❓", "huh?" );
echo ❓;
</code></pre>

<p>And, well, pretty much everywhere:</p>

<pre><code class="language-php">class 🦜
{
    public int $🐦;
    public ?string $🦃;

    public function __construct(int $🐦, ?string $🦃)
    {
        $this-&gt;🐦 = $🐦;
        $this-&gt;🦃 = $🦃;
    }
}
$🐓 = new 🦜(1234, "birb");
echo $🐓-&gt;🐦;
</code></pre>

<p>How about namespaces? Yup!</p>

<pre><code class="language-php">namespace 😜;
class 😉 {
    public function 😘() {
        echo "Wink!";
    }
}

use 😜\😉;
$😊 = new 😉();
$😊-&gt;😘();
</code></pre>

<p>Even moderately complex Unicode sequences work:</p>

<pre><code class="language-php">echo &lt;&lt;&lt;🏳️‍🌈
Unicode is magic!
🏳️‍🌈;
</code></pre>

<p>I've written before about the <a href="https://shkspr.mobi/blog/2019/06/quirks-and-limitations-of-emoji-flags/">Quirks and Limitations of Emoji Flags</a>. The humble 🏳️‍🌈 is actually the sequence U+1F3F3 (white flag), U+FE0F (Variation Selector 16), U+200D (Zero Width Joiner), U+1F308 (Rainbow).</p>

<p>Take a complex emoji like "<a href="https://emojipedia.org/astronaut-medium-dark-skin-tone">Female Astronaut with Medium Dark Skin Tone</a>" - 🧑🏾‍🚀 - that also works!</p>

<pre><code class="language-php">$🧑🏾‍🚀 = 1;
$👷🏻‍♂️ = 2;
echo $🧑🏾‍🚀 + $👷🏻‍♂️;
</code></pre>

<p>Probable the <a href="https://unicode.run/#run=%F0%9F%A7%91%F0%9F%8F%BE%E2%80%8D%E2%9D%A4%EF%B8%8F%E2%80%8D%F0%9F%92%8B%E2%80%8D%F0%9F%A7%91%F0%9F%8F%BB">most complex emoji</a> has <strong>10</strong> different codepoints!  It looks like this - 🧑🏾‍❤️‍💋‍🧑🏻</p>

<p>And it works!</p>

<pre><code class="language-php">$🧑🏾‍❤️‍💋‍🧑🏻 = "Kiss Kiss. Bang Bang!";
echo $🧑🏾‍❤️‍💋‍🧑🏻[-1];
</code></pre>

<p>There are some emoji which don't work;</p>

<pre><code class="language-php">$5️⃣ = "five";
</code></pre>

<p>The 5️⃣ emoji is U+0035 (Digit Five), U+FE0F (Variation Selector 16), U+20E3 (Combining Enclosing Keycap).  PHP doesn't allow variables to start with digits, so it craps out with <code>PHP Parse error:  syntax error, unexpected integer "5", expecting variable or "{" or "$" in php shell code on line 1</code></p>

<p>You also can't use "punctuation" emoji as though they were normal characters:</p>

<pre><code class="language-php">echo 5 ❗= 6;
</code></pre>

<p>And, while not <em>strictly</em> emoji, you can't use mathematical symbols:</p>

<pre><code class="language-php">echo 5 ≤ 6;
</code></pre>

<p>So, there you have it. Is this <em>useful</em>? Well, probably. It is easy to get lost in a sea of text - so little pictograms can make it easier to see what you're doing. If the basic ASCII characters aren't part of your native language, perhaps it is useful to make use of the full range of Unicode.</p>

<p>Does your favourite programming language support Emoji?</p>
<img src="https://shkspr.mobi/blog/wp-content/themes/edent-wordpress-theme/info/okgo.php?ID=50268&HTTP_REFERER=RSS" alt="" width="1" height="1" loading="eager">]]></content:encoded>
					
					<wfw:commentRss>https://shkspr.mobi/blog/2024/04/where-you-can-and-cant-use-emoji-in-php/feed/</wfw:commentRss>
			<slash:comments>5</slash:comments>
		
		
			</item>
	</channel>
</rss>
