Skip to content

Comment on Code that will only execute once

Comments

1) Create a file unlink.php in your php environment

2) Paste this in it <?php unlink('unlink.php');

3) Visit unlink.php on your browser

Any php file with the following should work.

<?php unlink(__FILE__);

With short open tags enabled the example can be simplified further as <?unlink(__FILE__);

It's been a couple of years since I programmed in PHP, but I'm pretty sure if it's the EOF you don't even need the final semicolon, so:

  <?unlink(__FILE__)

Short tags (other than echo <?=) are no longer on by d efault

Visit unlink.php on your browser

Better yet, make it an executable script starting with the line:

#!/usr/bin/php -q

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.