アプリ関連ニュース
- 2020年5月25日
- 技術情報
PHP Static methods
I will talk about static methods usages in php with some code samples. Lets get started.
Here is a sample, calling static function outside of the class.
<?php
class welcome {
public static function sayHi() {
echo "Welcome!";
}
}
// we can like this -> className::methodName()
welcome::sayHi();
?>
We can also call within the class like this using self::
<?php
class welcome {
public static function sayHi() {
echo "Welcome!";
}
public function msg() {
self::sayHi();
}
}
$hi = new welcome();
$hi->msg();
?>
You can also call static methods from another class like this
<?php
class welcome {
public static function sayHi() {
echo "Welcome!";
}
}
class anotherClass {
public function msg() {
welcome::sayHi();
}
}
$var = new anotherClass();
$var->msg();
?>
You can choose any ways depending upon the situations, the result will still be the same.
By Yuuma
yuuma at 2020年05月25日 11:00:23
- 2020年5月22日
- 技術情報
[Laravel] 設定ファイル「.env」の切り替えについて
nishida at 2020年05月22日 10:00:31
- 2020年5月18日
- 技術情報
Constants In PHP Object Oriented Programming
Today I will talk about constants which are very useful in development. Before we dive into code samples, there are a few things you have to remember.
- – It is declared inside a class with the const keyword.
- – They are case-sensitive. It’s better to name them all upper case letter for best practice.
- – We can access them back outside of the class with this operator (::)
Let’s see a simple constant and it has been called outside of the class.
<?php
class Welcome {
const HELLO_MSG = "Hello From Gigas!";
}
echo Welcome::HELLO_MSG;
// this will output "Hello From Gigas!"
?>
And also we can access the constant within the class like this using self keyword.
<?php
class Welcome {
const HELLO_MSG = "Hello From Gigas!";
public function sayHello() {
echo self::HELLO_MSG;
}
}
$hello = new Welcome();
$goodbye->sayHello();
// this too will output "Hello From Gigas!"
?>
By Yuuma
yuuma at 2020年05月18日 10:30:52
- 2020年5月15日
- 技術情報
[Laravel] データベースマイグレーション
Laravelのマイグレーション機能を使用することで、データベースのテーブル構造の反映をスクリプトとしてコマンドラインで実行することが可能になり、保守や変更作業などが簡単にできるようになります。
続きを読むnishida at 2020年05月15日 10:00:02
Visual Studio for Macを使って Xamarin.iOS アプリを作成
tanaka at 2020年05月13日 10:00:05