일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- IntelliJ
- laravel
- elasticsearch
- docker
- db
- Spring Boot
- AWS
- it
- php
- Git
- Oracle
- devops
- 맛집
- ReactJS
- springboot
- Spring
- redis
- MySQL
- Web Server
- 요리
- javascript
- jsp
- java
- jenkins
- tool
- Design Patterns
- ubuntu
- JPA
- linux
- Gradle
Archives
- Today
- Total
아무거나
PHP7 기준 빈 객체 생성 방법 본문
반응형
[PHP7 빈 객체 생성하는 방법]
In PHP 7 there are a few ways to create an empty object:
<?php
$obj1 = new \stdClass; // Instantiate stdClass object
$obj2 = new class{}; // Instantiate anonymous class
$obj3 = (object)[]; // Cast empty array to object
var_dump($obj1); // object(stdClass)#1 (0) {}
var_dump($obj2); // object(class@anonymous)#2 (0) {}
var_dump($obj3); // object(stdClass)#3 (0) {}
?>
$obj1 and $obj3 are the same type, but $obj1 !== $obj3. Also, all three will json_encode() to a simple JS object {}:
<?php
echo json_encode([
new \stdClass,
new class{},
(object)[],
]);
?>
Outputs: [{},{},{}]
반응형
'PHP > PHP' 카테고리의 다른 글
문자열중 마지막 문자 자르기 (0) | 2019.04.03 |
---|---|
클로저(clouser) (1) | 2019.04.03 |
SQLRelay 설치(커넥션풀링 라이브러리) (0) | 2019.04.02 |
trait (0) | 2019.04.02 |
php curl 옵션 (0) | 2019.04.01 |
Comments