Is PHP mature?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I've hit two problems recently that strike me as major issues.
Firstly, if you compare two objects for equality, and there is some
recursion involved internal to the object's structure, then PHP gives
an error.

Consider this:

$blob1 = new Blob ();
$blob2 = new Blob ();

$blob1->child = $blob2;
$blob2->child = $blob1;

$blob1 === $blob2 ? print 'equal' : print 'not equal';        // works
$blob1 ==  $blob2 ? print 'equal' : print 'not equal';        // fails

Class Blob
    public $child;

I reported this as a bug, and was told "that's how PHP works - not a

Secondly, today I find out that using session_start() is a good way to
pass objects from web page to page, UNLESS they use SimpleXML. As they
say, WTF?

I've found that this was also reported as a bug (by someone else), and
they received the same response. I find it very difficult to continue
with this language, not knowing what weirdo error is going to crop up
next and then to be told "It's supposed to do that"

Is there a workaround to the second problem? How does one share
objects between pages when using SimpleXML?

Re: Is PHP mature? wrote:
Quoted text here. Click to load it
In this case, what would you rather have PHP do? PHP can not give you
a definitive answer on whether there equal. It's bad programming.
Quoted text here. Click to load it

Re: Is PHP mature?

On Feb 28, 10:28 pm, wrote:
Quoted text here. Click to load it

simpleXML = XML dude... <.< serialize your object... pass it to the
XML... then load it back in the other page... its like serializing
objects (SDave_sessions) in a database... and the let the user reload
his/her session <.< i dont practically and see any functionality about
passing an object via XML... when there are easier ways.. and also

Re: Is PHP mature? schrieb:
Quoted text here. Click to load it

You did  not say what your script outputs. Please remember to always do
that in the future. Just saying "works" doesn't help if you and the
reader have different assumptions as to what the result should be.

The first comparison checks if the objects are identical. This can be
answered with no just by looking at the main variable hash tables. They
are stored in different locations => not equal.

The first comparison checks if the objects are equal, as in "they
evaluate to the same". Evaluation is a problem here, because blob1 has
blob2 as child, which has blob1 as child, which has... and so on. The
objects can never be fully evaluated so PHP can never tell if they
evaluate to the same. No error here.

The == can be a problem if you don't know just how sloppy it is. For
example, (2=="2blob") is true because the comparison for int and string
is the comparison of the integer values of both arguments and the string
"2blob" evaluates to 2.

Quoted text here. Click to load it

Not every object can be serialized (represented as a string), and this
is required for storing it in a session. Java shares this problem,
objects to be serialized must be instances of classes implementing the
Serializable interface. The problem is due to some classes being engine
internal, their state is not fully stored in PHP user space. This
improves the performance of such classes.

Quoted text here. Click to load it
You can try to export XML from your object, store that in the session,
and later reload it to a new object from this string. Even then,
remember that sessions are not meant for storing really big amounts of
data. Your data has to be exported as a giant serialized array and later
be reimported. The default way of storing a session is to save this
string to a plain text file! On the next request, this file has to be
read in and the string has to be parsed into an array. This is a big
potential performance bottleneck for your application. Try to store most
data in databases.

"You mess with a friend of Flinkman? You're messin' with Flinkman."
[Marshall, Alias 408]

Re: Is PHP mature?

I'm happy to say that I have worked out the second 'problem'. Turns
out that assigning the SimpleXML result to my object was assigning a
document fragment, and not the string or int as I had assumed. So:

$this->name = $document->name


$this->name = (string)$document->name

and everything works as expected. Wonderful! However, the way PHP just
crashes and blames the session not being available is more than a
little misleading.

The first problem I still see as a problem however. Why can't it just
compare the two memory addresses of the two objects and say "both
objects are at the same location, therefore they are equal", instead
of trying to traverse the data structures?

Thanks to those with helpful answers, raspberries to those without :)

Re: Is PHP mature? wrote:

Quoted text here. Click to load it

Because PHP, being a high-level language, does not allow the programmer to
work with pointers.

Quoted text here. Click to load it

Jeez, just RTFM:

On the other hand, when using the identity operator (===), object variables
are identical if and only if they refer to the same instance of the same

Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-
Proudly running Debian Linux with 2.6.17-1-amd64-k8 kernel, KDE3.5.3, and
PHP 5.2.0-8 generating this signature.
Uptime: 09:55:03 up 8 days, 14:55,  1 user,  load average: 0.22, 0.27, 0.19

Re: Is PHP mature? schrieb:
Quoted text here. Click to load it

I already told you that the "===" is meant for such comparisons and that
"==" is for totally different applications. And please try to forget
about memory locations. If you think about them again, then please ask
yourself why you didn't also think about manually freeing up the memory
at the end of your program ;-)


"Honey, the marriage counseling might not work out. You need to get used
to bad cooking."
[Bree on Desperate Housewives 105]

Re: Is PHP mature?

Oliver Grätz wrote:

Quoted text here. Click to load it

Back to malloc() memoryleaks.
Thoose were the days!

Erwin Moller

Quoted text here. Click to load it

Site Timeline