Site Links
Home
Features
Documentation
Pricing & Order
Members Area
Support Options
UBBDev.com
UBBWiki.com
Who's Online
2 registered (Dunny, Ruben), 48 Guests and 14 Spiders online.
Key: Admin, Global Mod, Mod
Featured Member
Registered: 06/05/06
Posts: 709
Top Posters (30 Days)
Ruben 50
DennyP 24
Gizmo 24
Dunny 15
SteveS 13
AllenAyres 12
dbremer 10
SD 10
drkknght00 9
driv 8
Latest Photos
OK Corral Shoot Out
Testing
Basildon Train Station
Basildon Town Centre looking from the rounderbout
Basildon Town Square
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: 1995
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 Offline
Registered: 04/19/07
Posts: 4056
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 Offline
Registered: 04/19/07
Posts: 4056
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 Offline
Registered: 04/19/07
Posts: 4056
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: 1995
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
Temporary Password email not being received
by
05/24/12 10:02 PM
Ability to "like" individual posts (not Facebook "likes)
by doug
05/23/12 09:03 AM
Island Permissions
by ThreadsUser
05/22/12 03:03 PM
streaming video
by prkrgrp
05/20/12 07:02 PM
New Posts Corrupted? Can someone help?
by PianoWorld
05/19/12 09:41 AM
Forum Stats
10492 Members
36 Forums
33842 Topics
181709 Posts

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