2 +----------------------------------------------------------------------+
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-2014 Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/runtime/base/complex-types.h"
18 #include "hphp/runtime/base/type-conversions.h"
19 #include "hphp/runtime/base/builtin-functions.h"
20 #include "hphp/runtime/base/variable-serializer.h"
21 #include "hphp/runtime/base/array-iterator.h"
22 #include "hphp/runtime/base/strings.h"
23 #include "hphp/runtime/ext/ext_collections.h"
24 #include "hphp/runtime/ext/ext_datetime.h"
26 #include "hphp/system/systemlib.h"
30 const Object
Object::s_nullObject
= Object();
32 ///////////////////////////////////////////////////////////////////////////////
35 // force it out of line
38 ArrayIter
Object::begin(const String
& context
/* = null_string */) const {
39 if (!m_px
) throw_null_pointer_exception();
40 return m_px
->begin(context
);
43 MutableArrayIter
Object::begin(Variant
*key
, Variant
&val
,
44 const String
& context
/*= null_string*/) const {
45 if (!m_px
) throw_null_pointer_exception();
46 return m_px
->begin(key
, val
, context
);
49 Array
Object::toArray() const {
50 return m_px
? m_px
->o_toArray() : Array();
53 int64_t Object::toInt64ForCompare() const {
54 check_collection_compare(m_px
);
58 double Object::toDoubleForCompare() const {
59 check_collection_compare(m_px
);
63 bool Object::equal(CObjRef v2
) const {
64 if (m_px
== v2
.get()) {
67 if (!m_px
|| !v2
.get()) {
70 if (m_px
->isCollection()) {
71 return collectionEquals(m_px
, v2
.get());
73 if (v2
.get()->getVMClass() != m_px
->getVMClass()) {
76 if (UNLIKELY(m_px
->instanceof(SystemLib::s_ArrayObjectClass
))) {
77 // Compare the whole object, not just the array representation
78 Array
ar1(ArrayData::Create());
79 Array
ar2(ArrayData::Create());
80 m_px
->o_getArray(ar1
, false);
81 v2
->o_getArray(ar2
, false);
82 return ar1
->equal(ar2
.get(), false);
84 if (UNLIKELY(m_px
->instanceof(c_DateTime::classof()))) {
85 return getTyped
<c_DateTime
>()->gettimestamp() ==
86 v2
.getTyped
<c_DateTime
>()->gettimestamp();
88 return toArray().equal(v2
.toArray());
91 bool Object::less(CObjRef v2
) const {
92 check_collection_compare(m_px
, v2
.get());
93 if (UNLIKELY(m_px
->instanceof(c_DateTime::classof()))) {
94 return getTyped
<c_DateTime
>()->gettimestamp() <
95 v2
.getTyped
<c_DateTime
>()->gettimestamp();
97 return m_px
!= v2
.m_px
&& toArray().less(v2
.toArray());
100 bool Object::more(CObjRef v2
) const {
101 check_collection_compare(m_px
, v2
.get());
102 if (UNLIKELY(m_px
->instanceof(c_DateTime::classof()))) {
103 return getTyped
<c_DateTime
>()->gettimestamp() >
104 v2
.getTyped
<c_DateTime
>()->gettimestamp();
106 return m_px
!= v2
.m_px
&& toArray().more(v2
.toArray());
109 static Variant
warn_non_object() {
110 raise_warning("Cannot access property on non-object");
111 return uninit_null();
114 Variant
Object::o_get(const String
& propName
, bool error
/* = true */,
115 const String
& context
/* = null_string */) const {
116 if (UNLIKELY(!m_px
)) return warn_non_object();
117 return m_px
->o_get(propName
, error
, context
);
120 Variant
Object::o_set(const String
& propName
, CVarRef val
,
121 const String
& context
/* = null_string */) {
123 setToDefaultObject();
125 return m_px
->o_set(propName
, val
, context
);
128 Variant
Object::o_setRef(const String
& propName
, CVarRef val
,
129 const String
& context
/* = null_string */) {
131 setToDefaultObject();
133 return m_px
->o_setRef(propName
, val
, context
);
136 Variant
Object::o_set(const String
& propName
, RefResult val
,
137 const String
& context
/* = null_string */) {
138 return o_setRef(propName
, variant(val
), context
);
141 ///////////////////////////////////////////////////////////////////////////////
144 void Object::serialize(VariableSerializer
*serializer
) const {
146 m_px
->serialize(serializer
);
148 serializer
->writeNull();
152 bool Object::unserialize(std::istream
&in
) {
153 throw NotImplementedException(__func__
);
156 void Object::setToDefaultObject() {
157 raise_warning(Strings::CREATING_DEFAULT_OBJECT
);
158 operator=(SystemLib::AllocStdClassObject());
161 ///////////////////////////////////////////////////////////////////////////////