blog,
@blog@shkspr.mobi avatar

Where you can (and can't) use Emoji in PHP
https://shkspr.mobi/blog/2024/04/where-you-can-and-cant-use-emoji-in-php/

I was noodling around in PHP the other day and discovered that this works:

<?php$๐Ÿž = "bread";echo "Some delicious " . $๐Ÿž;

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

Emoji work perfectly well as function names:

function ๐Ÿ˜บ๐Ÿถ() {   echo "catdog!";}๐Ÿ˜บ๐Ÿถ();

Definitions:

define( "โ“", "huh?" );echo โ“;

And, well, pretty much everywhere:

class ๐Ÿฆœ{    public int $๐Ÿฆ;    public ?string $๐Ÿฆƒ;    public function __construct(int $๐Ÿฆ, ?string $๐Ÿฆƒ)    {        $this->๐Ÿฆ = $๐Ÿฆ;        $this->๐Ÿฆƒ = $๐Ÿฆƒ;    }}$๐Ÿ“ = new ๐Ÿฆœ(1234, "birb");echo $๐Ÿ“->๐Ÿฆ;

How about namespaces? Yup!

namespace ๐Ÿ˜œ;class ๐Ÿ˜‰ {    public function ๐Ÿ˜˜() {        echo "Wink!";    }}use ๐Ÿ˜œ๐Ÿ˜‰;$๐Ÿ˜Š = new ๐Ÿ˜‰();$๐Ÿ˜Š->๐Ÿ˜˜();

Even moderately complex Unicode sequences work:

echo <<<๐Ÿณ๏ธโ€๐ŸŒˆUnicode is magic!๐Ÿณ๏ธโ€๐ŸŒˆ;

I've written before about the Quirks and Limitations of Emoji Flags. The humble ๐Ÿณ๏ธโ€๐ŸŒˆ is actually the sequence U+1F3F3 (white flag), U+FE0F (Variation Selector 16), U+200D (Zero Width Joiner), U+1F308 (Rainbow).

Take a complex emoji like "Female Astronaut with Medium Dark Skin Tone" - ๐Ÿง‘๐Ÿพโ€๐Ÿš€ - that also works!

$๐Ÿง‘๐Ÿพโ€๐Ÿš€ = 1;$๐Ÿ‘ท๐Ÿปโ€โ™‚๏ธ = 2;echo $๐Ÿง‘๐Ÿพโ€๐Ÿš€ + $๐Ÿ‘ท๐Ÿปโ€โ™‚๏ธ;

Probable the most complex emoji has 10 different codepoints! It looks like this - ๐Ÿง‘๐Ÿพโ€โค๏ธโ€๐Ÿ’‹โ€๐Ÿง‘๐Ÿป

And it works!

$๐Ÿง‘๐Ÿพโ€โค๏ธโ€๐Ÿ’‹โ€๐Ÿง‘๐Ÿป = "Kiss Kiss. Bang Bang!";echo $๐Ÿง‘๐Ÿพโ€โค๏ธโ€๐Ÿ’‹โ€๐Ÿง‘๐Ÿป[-1];

There are some emoji which don't work;

$5๏ธโƒฃ = "five";

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 PHP Parse error: syntax error, unexpected integer "5", expecting variable or "{" or "$" in php shell code on line 1

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

echo 5 โ—= 6;

And, while not strictly emoji, you can't use mathematical symbols:

echo 5 โ‰ค 6;

So, there you have it. Is this useful? 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.

Does your favourite programming language support Emoji?

https://shkspr.mobi/blog/2024/04/where-you-can-and-cant-use-emoji-in-php/

  • All
  • Subscribed
  • Moderated
  • Favorites
  • โ€ข
  • php
  • DreamBathrooms
  • magazineikmin
  • ethstaker
  • InstantRegret
  • tacticalgear
  • rosin
  • love
  • Youngstown
  • slotface
  • ngwrru68w68
  • kavyap
  • cubers
  • thenastyranch
  • mdbf
  • megavids
  • cisconetworking
  • GTA5RPClips
  • modclub
  • khanakhh
  • everett
  • Leos
  • osvaldo12
  • normalnudes
  • tester
  • Durango
  • anitta
  • provamag3
  • JUstTest
  • All magazines