473,405 Members | 2,334 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Is PHP mature?

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
bug"

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?

Mar 1 '07 #1
7 1447

de***********@gmail.com wrote:
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
bug"
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.
>
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?
Mar 1 '07 #2
469
On Feb 28, 10:28 pm, denisbytez...@gmail.com wrote:
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
bug"

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?

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
faster...

Mar 1 '07 #3
de***********@gmail.com schrieb:
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
bug"
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.
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?
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.
Is there a workaround to the second problem? How does one share
objects between pages when using SimpleXML?
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.

OLLi
____________
"You mess with a friend of Flinkman? You're messin' with Flinkman."
[Marshall, Alias 408]
Mar 1 '07 #4
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

becomes

$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 :)

Mar 1 '07 #5
de***********@gmail.com wrote:
The first problem I still see as a problem however. Why can't it just
compare the two memory addresses of the two objects
Because PHP, being a high-level language, does not allow the programmer to
work with pointers.
and say "both objects are at the same location, therefore they are equal",
instead of trying to traverse the data structures?
Jeez, just RTFM:

http://es.php.net/manual/en/language...comparison.php

"
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
class.
"

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

http://acm.asoc.fi.upm.es/~mr/
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

Mar 1 '07 #6
de***********@gmail.com schrieb:
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?
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 ;-)

OLLi

____________
"Honey, the marriage counseling might not work out. You need to get used
to bad cooking."
[Bree on Desperate Housewives 105]
Mar 1 '07 #7
Oliver Grätz wrote:
de***********@gmail.com schrieb:
>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?

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 ;-)
Yeah!
Back to malloc() memoryleaks.
Thoose were the days!
;-)

Regards,
Erwin Moller
>
OLLi

____________
"Honey, the marriage counseling might not work out. You need to get used
to bad cooking."
[Bree on Desperate Housewives 105]
Mar 1 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Aubrey Hutchison | last post by:
### this will test if your version of IDLE on windows is a MATURE program design ### print "Hello world, If Python IDLE is a mature program design it will output this" Save this simple...
7
by: Mickel Grönroos | last post by:
Hi everybody, To the heart of the matter: Which of the available Soap modules is best fitted for client side soap messaging? I have an upload service (written in Perl) that I want to use from a...
8
by: The unProfessional | last post by:
To the VC .Net'ers out there... I noticed alot of strange behavior in the way VC .Net apps behave in the IDE. It's a bit odd, so maybe people have workarounds. I'm worried to devote my project...
34
by: Guch Wu | last post by:
Boost has many terrific libraries. But I want to know whether they are ready for using in real projects. Which of them are mature enough, or just only in progress?
0
by: black mature bbw | last post by:
Hqn: kgabpux at ufk - <a href='http://enticemusic.com/phpBB/doors/older-ass/1048575.html#black mature bbw'>black mature bbw</ain a kyjgf! The vrix - uzx is <a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.