Site Links
Home
Features
Documentation
Pricing & Order
Members Area
Support Options
UBBDev.com
UBBWiki.com
Who's Online
6 registered (Ruben, SD, nims2, Dunny, GregK, SteveS), 22 Guests and 14 Spiders online.
Key: Admin, Global Mod, Mod
Featured Member
mig
mig
Registered: 07/22/05
Posts: 39
Top Posters (30 Days)
Ruben 65
SD 57
Gizmo 53
gliderdad 32
Iann128 22
Dunny 21
Steve C 20
driv 18
dbremer 16
Stan 15
Latest Photos
Testing
Basildon Train Station
Basildon Town Centre looking from the rounderbout
Basildon Town Square
Gizzo Marx
Topic Options
#223551 - 03/04/09 06:03 AM Strange (invalid??) PHP code
Mattie Offline
stranger
Registered: 03/04/09
Posts: 15
I come across many strangely used isset(..) syntax in many files, mainly in the scripts folder:
Php Code:

	$BodySig = $Body;
	isset($user['USER_AVATAR']) && $Picture = $user['USER_AVATAR'];
	if (!isset($Picture)) { $Picture = "http://"; }
 


Just look at the second line. And there are many more like these throughout the code.
I cannot help think that this must be remainders of old if(...) statements. Can you explain what is supposed to happen here?
Top
Express Hosting
Express Hosting "We are the official hosting company of UBB.threads. Ask us about our free migration services to migrate your UBB.threads installation."
#223662 - 03/06/09 11:49 AM Re: Strange (invalid??) PHP code [Re: Mattie]
AllenAyres Offline

Registered: 12/29/03
Posts: 1982
Loc: Texas
isset — Determine whether a variable is set

http://us.php.net/isset

I check the manual at php.net when I'm trying to figure out what is going on.
_________________________
- Allen
- ThreadsDev | PraiseCafe
Top
#223670 - 03/06/09 01:41 PM Re: Strange (invalid??) PHP code [Re: AllenAyres]
Mattie Offline
stranger
Registered: 03/04/09
Posts: 15
No need to get cynical. I use my php_manual.chm frequently, but never seen isset been used like that.

As I see it, line 2 in the above code reads as one of the following 2 options:
Php Code:
false and $Picture = $user['USER_AVATAR']; 

or
Php Code:
true and $Picture = $user['USER_AVATAR']; 


This only makes sense if php uses a construct called "complete boolean evaluation". I know this construct from basic, but I've never seen it be used in php.

But hey, maybe php does indeed behave the same and break an evaluation as soon as an "and" clause hits a "false" condition.
Still, even if that's the case, I wonder why you would write your code like that. If you code it like in line 3, it requires only 1 character more, but it would be a proper "if" clause which will never fail. Not even if the syntax rules in a next php version be changed to not break an evaluation upon the first "false".

Just my 2 cents.
Top
#223699 - 03/06/09 07:23 PM Re: Strange (invalid??) PHP code [Re: Mattie]
SD Online   partay
Registered: 04/19/07
Posts: 4031
Loc: SoCal, USA
lol -- i don't think allen was being cynical at all.. his post perty much mirrors what i might have posted..

php.net is where i refer to all the time wink


and the code makes sense.. $Picture only gets assigned, if there is a variable that is set in the 1st place..

if it's false, the code doesn't continue on...

there are other ways to skin this cat too, but that works.. wink
_________________________

Threads tutorials . Threads & Wordpress experts . UBB resume

If I you, click this link as to why
Top
#223714 - 03/07/09 04:26 AM Re: Strange (invalid??) PHP code [Re: SD]
Mattie Offline
stranger
Registered: 03/04/09
Posts: 15
Thanks Sirdude, but I find it a sound cynical to refer to the manual and quote the isset explanation. Especially since that doesn't answer the question.

I do use my php_manual.chm very often and did so too when I ran into this code. I just never was able to find a construct like the one used, hence my question.

It's one thing to know where to look (php manual and many websites) but it's another thing to know what to look for. Not isset that's for sure...
This morning I woke up and realised I had probably been looking in the wrong place all the time.

Just like Allen did, I too looked for isset, while in fact I should have looked at the && evaluation. And indeed there it's explained perfectly.

I do now understand that this code:
Php Code:
isset($user['USER_AVATAR']) && $Picture = $user['USER_AVATAR'];
if (!isset($Picture)) { $Picture = "http://"; }
 


does exactly the same as this code:
Php Code:
if (isset($user['USER_AVATAR'])) $Picture = $user['USER_AVATAR'];
if (!isset($Picture)) { $Picture = "http://"; }
 


But why would one opt for 2 different styles of evaluating an isset in 2 consecutive lines?
That still puzzles me.
Top
#223725 - 03/07/09 12:00 PM Re: Strange (invalid??) PHP code [Re: Mattie]
SD Online   partay
Registered: 04/19/07
Posts: 4031
Loc: SoCal, USA
lol, i have bigger fish to fry.. you can ponder all you want, my explanation showed how the logic evaluated..

and i DID re-check over at php.net, just to make sure before i posted.. i guess that makes me 'cynical' laugh

so all is one with the force now, i guess..

and like i said, you can do it many other ways:

eg
Php Code:
$Picture = isset($user['USER_AVATAR']) ? $user['USER_AVATAR'] : 'http://'; 


i'd say it's there more so as a legacy dealio.. threads has been around for awhile now and i've noticed different ways of doing things..
_________________________

Threads tutorials . Threads & Wordpress experts . UBB resume

If I you, click this link as to why
Top
#223728 - 03/07/09 12:36 PM Re: Strange (invalid??) PHP code [Re: SD]
Mattie Offline
stranger
Registered: 03/04/09
Posts: 15
Reading your reply, I'm starting to think that we have been on different wave length from the start.

My problem was not that I don't understand isset. My problem was that I didn't know about the so called "short circuit" evaluation in php.

Ofcourse that's my shortcomming, but that's why I couldn't find an answer in the isset explanation.
Top
#223729 - 03/07/09 12:51 PM Re: Strange (invalid??) PHP code [Re: Mattie]
SD Online   partay
Registered: 04/19/07
Posts: 4031
Loc: SoCal, USA


no problemo.. wink
_________________________

Threads tutorials . Threads & Wordpress experts . UBB resume

If I you, click this link as to why
Top
#223730 - 03/07/09 02:12 PM Re: Strange (invalid??) PHP code [Re: SD]
AllenAyres Offline

Registered: 12/29/03
Posts: 1982
Loc: Texas
hehe, I answered the question you asked. Not being a developer myself, I go to the manual at php.net if I don't understand something. We have no idea what level a person is when they come to this forum to ask a question so I try to answer based on the perceived level of coding skills smile I am definitely not cynical and meant no put-down to anyone who might understand php, especially better than me smile
_________________________
- Allen
- ThreadsDev | PraiseCafe
Top
#223772 - 03/08/09 05:01 AM Re: Strange (invalid??) PHP code [Re: AllenAyres]
Mattie Offline
stranger
Registered: 03/04/09
Posts: 15
No hard feelings.
Looks like I should have phrased my question different.
At the time it just felt like beeing put down because I had been looking for an answer to my "problem" for weeks. And if someone then tells me to "go look at php.net" and quotes something I have read dozens of times over the past weeks...
Well I think it's clear how I felt wink
Top



Moderator:  AllenAyres, Harold, Ian, Ron M 
Shout Box

Today's Birthdays
No Birthdays
Recent Topics
A positive note
by SteveS
Yesterday at 09:36 PM
How to locate links to particular site if they are only used in images?
by Conrad
02/10/12 09:41 PM
Pictures not displaying
by Marker23
02/09/12 10:04 PM
Issue with logging out constantly
by Flanuva
02/09/12 07:05 PM
Long thread, UBB code not parsing
by Bad Frog
02/09/12 07:47 AM
Forum Stats
10213 Members
36 Forums
33666 Topics
180902 Posts

Max Online: 978 @ 06/24/07 11:19 PM
Random Image