new clone違い

演算子

 状態:  閲覧数:6,448  投稿日:2010-05-06  更新日:  

「new」 - クラスのインスタンスつまりオブジェクトを生成する際に利用
「clone」 - オブジェクトのクローン(コピー)を格納する際に利用

<pre>
<?php
class COLOR{
//empty
}

#オブジェクトの生成
var_dump( new COLOR );

#オブジェクトのクローンの生成
$n = new COLOR;
var_dump( clone $n );
?>
</pre>

▼結果
  /demo/clone.html


結合時の評価と優先順位

and

コメント投稿(ログインが必要)



類似度ページランキング
順位 ページタイトル抜粋
1 new clone違い 82
2 define と const の違い 48
3 include 44
4 Doctrine 42
5 include require 38
6 popen 38
7 Propel 35
8 syntax error 35
9 include_path 35
10 Exceptionクラス 35
11 SessionHandler::gc 34
12 json_encode関数 33
13 foreach文 32
14 session.gc_maxlifetime 30
15 Composer 30
16 set_error_handler 29
17 ErrorExceptionクラス 29
18 No route found fo 29
19 Generators 29
20 setcookie関数 27
2026/8/24 3:33 更新
週間人気ページランキング / 8-16 → 8-22
順位 ページタイトル抜粋 アクセス数
1 PHP用語 16
2 実際に遭遇した例1. 6
3 定数 3
4 SQLインジェクション | セキュリティ 2
4 _FILE__ | 定数 2
4 P … 親クラスインスタンス生成。親クラス内での$this 2
4 Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 23 Out of resources when opening file '/tmp/#sql_2dd6_0.MYI' (Errcode: 24)' | エラーメッセージ 2
4 set_error_handler | 例外処理(制御構造) 2
4 セッションのガベージコレクション (ごみの収集)はなぜ必要なの? 2
4 ( ! ) Deprecated: implode(): Passing glue string after array is deprecated. Swap the parameters in ★★★ headless-chromium-php/vendor/wrench/wrench/lib/Wrench/Protocol/Protocol.php | エラーメッセージ 2
4 PHPにおけるメソッドのオーバーライドについて /「引数の数や型は、親クラスのメソッドと完全に一致していなければなりません。」とは具体的にどういう意味ですか? 2
5 popen | ファイルシステム (関数) 1
5 エラーメッセージ / エラー原因 / 遭遇例 1 1
5 タイプヒンティング | クラスとオブジェクト 1
5 エラー | 例外処理(制御構造) 1
5 メタキャラクタ 1
5 PHPで定数を定義する方法は2種類ある / 配列定数の定義 1
5 Fatal error: require_once(): Failed opening required 'PEAR.php' | Fatal error(エラーメッセージ) 1
5 __toString()メソッド 1
5 マジックメソッド(クラスとオブジェクト) カテゴリー 1
2026/8/23 5:05 更新