Для получения полного доступа
зарегистрируйтесь.
RSS

All snippets tagged with "php7" tag



Gravatar image
tetraset
  • Reputation: 6
  • Snippets: 3
  • Revisions: 0
function chunkedCopy($from, $to) {
    # 1 meg at a time, you can adjust this.
    $buffer_size = 1048576;
    $ret = 0;
    $fin = fopen($from, "rb");
    $fout = fopen($to, "w");
    while(!feof($fin)) {
    	$ret += fwrite($fout, fread($fin, $buffer_size));
    }
    fclose($fin);
    fclose($fout);
    return $ret;
}
dfatt
  • Reputation: 260
  • Snippets: 53
  • Revisions: 7

In C++, C# etc. you know what will be returned from a method. No surprises such as getting a string instead of expected int.

Using PHP 7 you can finally specify return type!

class Post extends CI_Model {

	public function __construct() {
		$this->load->database();
		$this->load->helper(['url', 'date']);
	}

	/**
	 * Getting post by ID
	 * @param $id
	 * @return array
	 */
	public function get_post_by_id($id): array {
		$query = $this->db->where('id', $id)->get('post');
		return ! is_null($query->row()) ? $query->row() : [];
	}
}