Skip to content

Instantly share code, notes, and snippets.

View kpion's full-sized avatar

Konrad Papała kpion

View GitHub Profile
Create two files:
PHP file get_image.php:
<?php
//you'll play with dirs / paths later
$file = 'some_image.png';
$type = 'image/png';
header('Content-Type:'.$type);
header('Content-Length: ' . filesize($file));
<?php
/**
* Disclaimer - I am aware using __call to set things isn't anything new, once upon a time, I created an ORM class doing that, but this
* time I'd like to ask about using this approach actually everytime we need accessors like set/get.
*
* OK, so using accessors is a good practice. But quite boring, isn't it? Even with all this IDEs' support (menu code -> create accessors for me please).
*
* Why not use the __call magic method catching "get/set" methods?
*
@kpion
kpion / phpdoc-var-type.php
Last active February 10, 2017 12:47
Why would we want to type hint variables via php doc
<?php
/**
Here is an example of type hinting variables (not function parameters), using php doc.
There is only one reason for doing this - to let IDEs know what is what.
*/
class X{
public function blahx(){
echo 'blahx';
}
<?php
/**
It's about a different way of passing params to an sql query. Yes, still using PDO behind the scenes.
*/
///////////////////////////
//The standard way of passing params:
$stmt = $dbh->prepare("INSERT INTO some_table (first_name, last_name) VALUES (?, ?)");
$stmt->bindValue(1, $_GET['first_name']);