Skip to content

Instantly share code, notes, and snippets.

@gmemstr
Created May 29, 2019 19:37
Show Gist options
  • Save gmemstr/49e7c7ced92a7d5574a84a34f33db49f to your computer and use it in GitHub Desktop.
Save gmemstr/49e7c7ced92a7d5574a84a34f33db49f to your computer and use it in GitHub Desktop.
<?php
/**
* @file
* Self-altering PHP counting script. Ideal for lambdas?
*/
$count = 3;
$thisFile = fopen(__FILE__, 'r');
$thisFileContents = fread($thisFile, filesize(__FILE__));
$thisFileContents = str_replace('$count = ' . $count . ';', '$count = ' . ($count + 1). ';', $thisFileContents);
$thisFile = fopen(__FILE__, 'w');
fwrite($thisFile, $thisFileContents);
echo $count;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment