技術情報

[Laravel] データベースマイグレーション

Laravelのマイグレーション機能を使用することで、データベースのテーブル構造の反映をスクリプトとしてコマンドラインで実行することが可能になり、保守や変更作業などが簡単にできるようになります。

続きを読む

Trait in PHP Object Oriented Programming

Today I will talk about trait and its sample usages.In the Object Oriented Inheritance, a child class can only extend only one parent class.So what if the child class has to extend more than one parent classes? OOP trait is the answer for this problem as child classes can extend many traits as they want.Check out the samples below.

Here is the sample usage of a trait

<?php
trait Trait1 {
  public function print() {
    echo "lets extend more than one trait!"; 
  }
}

class Home {
  use Trait1;
}

$obj = new Home();
$obj->print();
?>

Now, Lets extend more than one trait.

<?php
trait Trait1 {
  public function print1() {
    echo "I am the trait1"; 
  }
}

trait Trait2 {
  public function print2() {
    echo "I am the trait2"; 
  }
}

class Home {
  use Trait1,Trait2;
}

$obj = new Home();
$obj->print1();
$obj->print2();
?>

By Yuuma



[Laravel] バリデーションエラーメッセージの日本語化

Laravel標準のバリデーション機能を使用した場合、英語でエラーメッセージが表示されます。
今回はLaravelのエラーメッセージの日本語化をおこなう方法を説明いたします。

続きを読む

[Laravel]バリデーション機能の使用

今回はLaravelフレームワークに標準搭載されているバリデーション機能の基本的な使用方法の説明をおこないたいと思います。

続きを読む

Isset VS Empty In PHP

Today I will walk through the difference between isset & empty , build in functions in PHP.

Iseet

It checks the variable to see if it has been set, in other words, it checks to see if the variable is any value except NULL or not assigned a value. ISSET returns TRUE if the variable exists and has a value other than NULL. That means variables assigned a ” “, 0, “0”, or FALSE are set, and therefore are TRUE for ISSET.

Empty

It checks to see if a variable is empty. Empty is interpreted as: ” ” (an empty string), 0 (0 as an integer), 0.0 (0 as a float), “0” (0 as a string), NULL, FALSE, array() (an empty array), and “$var;” (a variable declared, but without a value in a class.)

Lets do some comparisons.

Non declared variable

isset($novar) – Return FALSE
empty($novar) – Return TRUE

Null Variable

$null = NULL; 
isset ($null) - Return FALSE 
empty ($null) - Return TRUE

Empty String

$emptyString = ""; 
isset($emptyString) - Return TRUE 
empty($emptyString) - Return TRUE 

This will be the same result for zero case.

Boolean value

$tbl = TRUE; 
$fbl = FALSE; 

Isset . Will Return TRUE For Both Cases
Empty

empty($tbl) - Return FALSE 
empty($fbl) - Return TRUE

Empty Array

$arr = [];
The result will be true for both isset and empty

Empty object

$obj = new stdClass (); 
isset ($obj) – return TRUE 
empty ($obj) – return FALSE

Note: Isset only accepts single variable within its parenthesis. Passing others will proceed to error. For example
isset(strtoupper($var)) – this will proceed to error.

By Yuuma




アプリ関連ニュース

お問い合わせはこちら

お問い合わせ・ご相談はお電話、またはお問い合わせフォームよりお受け付けいたしております。

tel. 06-6454-8833(平日 10:00~17:00)

お問い合わせフォーム