Learning Diary, PHP weird symbol, 学习笔记,PHP怪符号
Hello Steemit friends, so I was learning PHP and discovered so many symbol were used in PHP programming language, such as __, @, ->, =>, :: so let list them down and study them all
大家好,今天继续学习PHP,发现里面的怪符号都有不同的功能,就让我们一起学习吧
The use of __ (two underscore)
- this is use for all the translation of the language, example
这个是用来翻译用的,在所有你要翻译的字的前面加这个符号,以后要翻译就容易
echo __("Hello, world!"); // Bonjour, monde!
So if you have 3 language, when you switch the language, it will switch to the language you choose
The use of @ in front of the function
- this will suppress all warning or error so that it won’t crash your website but you will never know what is the error
这个是用来避免电脑告诉你错误,免的网站运行不到,可是这样一来有什么错误你就不会知道
Example
$fileHandle = @fopen($fileName, $writeAttributes);
since you put the @ in front of the function fopen, so if you failed to open the file for any reason the computer will never tell you
The use of =>
- this is used to assign values to the keys of an array
这个是用来给你的array设定数据
Example
$myArray = array(
0 => 'Big',
1 => 'Small',
2 => 'Up',
3 => 'Down'
);
The use of ->
- this is used to access method or property of an object
这个是用来拿object里的method或property
Example
// Create a new instance of MyObject into $obj
$obj = new MyObject();
// Set a property in the $obj object called thisProperty
$obj->thisProperty = 'Fred';
// Call a method of the $obj object named getProperty
$obj->getProperty();
The use of ::
is a token that allows access to static, constant, and overridden properties or methods of a class
这个用来读取object里的constant variable
Example
<?php
class MyClass {
const CONST_VALUE = 'A constant value';
}
echo MyClass::CONST_VALUE;
?>
thanks for reading
谢谢阅读
Hi ~ I'm a robot of januschoi.I just upvoted your post!
Please come visit me here: https://steemit.com/@januschoi
Thanks so much~!!
PHP 好坑的,哈哈
STOP
你今天过的开心吗?听说有才的人都去参加 “三个一” 活动了呢,你要不要去耍耍?如果我打扰到你,请回复“取消”。
You've been upvoted by TeamMalaysia Community :-
To support the growth of TeamMalaysia Follow our upvotes by using steemauto.com and follow trail of @myach
Vote TeamMalaysia witness bitrocker2020 using this link vote for witness