Topic: The Read, Write and Erase Pattern

Native PHP has super-global variables that we used them pretty much in common such as $_COOKIE $_GET, $_POST and $_SESSION. We already have classes named Cookie and Session which work as how they should. We also have Get class which work a bit different.

I am thinking about making a class pattern like the native PHP super-global variables pattern. I mean, we have $_REQUEST which is basically works as a parent of $_COOKIE, $_ENV, $_GET, $_POST, $_SERVER and $_SESSION.

We already have Request class which handle most of them properly. Just some methods that I don’t like because of the hard-coded function arguments especially for methods that are used to set $_GET and $_POST value dynamically:

Request::set('post', 'title', 'Hello');
Request::set('get', 'title', 'Hello');

Which is much readable in any way when proposed to be like this:

Request::setPost('title', 'Hello');
Request::setGet('title', 'Hello');

But we have to survive so that we can use single word for class and method names where possible, for the sake of this article.

class Request extends Genome {}
class Cookie extends Request {}
class Environment extends Request {}
class Get extends Request {}
class Post extends Request {}
class Server extends Request {}
class Session extends Request {}


Even more, aside of Request::post() and Request::server(), the Request::get() method already break my get-reset-set pattern for a long time.

And because of this, I probably will rename Page::data() to Page::set() and rename File::write() to File::set().

Re: The Read, Write and Erase Pattern

Is::get() → !empty($_GET)
Is::set() → !empty($_POST)
Get::get('title') → $_GET['title'] ?? null
Set::get('title') → $_POST['title'] ?? null
Get::set('title', 'Hello') → $_GET['title'] = 'Hello'
Set::set('title', 'Hello') → $_POST['title'] = 'Hello'


Re: The Read, Write and Erase Pattern


Drop native support for PHP curl and use HTTP::get() in place Request::get(), HTTP::post() in place Request::post().


  • No need PHP curl dependency.

  • Reduce file size (we can remove the Request class completely from the library).

  • Shorter declaration form (Request::post() vs HTTP::post(), 15 vs 12).