Site Links
Home
Features
Documentation
Pricing & Order
Members Area
Support Options
UBBDev.com
UBBWiki.com
Who's Online Now
1 registered members (mmkk), 71 guests, and 386 spiders.
Key: Admin, Global Mod, Mod
Member Spotlight
M4TT
M4TT
Canada, SK
Posts: 51
Joined: March 2015
Show All Member Profiles 
Top Posters(30 Days)
Gizmo 18
M4TT 12
FREAK 11
Ruben 8
mmkk 5
isaac 4
Latest Photos
Chinese Buddhist temple.
My buddha beads.
Rendered Walls
Multi-Screen wallpaper
Stockholm Metro
Previous Thread
Next Thread
Print Thread
Strange (invalid??) PHP code #223551
03/04/09 06:03 AM
03/04/09 06:03 AM
Joined: Mar 2009
Posts: 15
M
Mattie Offline OP
stranger
Mattie  Offline OP
stranger
M
Joined: Mar 2009
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?

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."
Re: Strange (invalid??) PHP code [Re: Mattie] #223662
03/06/09 11:49 AM
03/06/09 11:49 AM
Joined: Dec 2003
Posts: 2,046
Texas
AllenAyres Offline
Pooh-Bah
AllenAyres  Offline
Pooh-Bah
Joined: Dec 2003
Posts: 2,046
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
Re: Strange (invalid??) PHP code [Re: AllenAyres] #223670
03/06/09 01:41 PM
03/06/09 01:41 PM
Joined: Mar 2009
Posts: 15
M
Mattie Offline OP
stranger
Mattie  Offline OP
stranger
M
Joined: Mar 2009
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.

Re: Strange (invalid??) PHP code [Re: Mattie] #223699
03/06/09 07:23 PM
03/06/09 07:23 PM
Joined: Apr 2007
Posts: 4,313
SoCal, USA
SD Offline
Carpal Tunnel
SD  Offline
Carpal Tunnel
Joined: Apr 2007
Posts: 4,313
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

Re: Strange (invalid??) PHP code [Re: SD] #223714
03/07/09 04:26 AM
03/07/09 04:26 AM
Joined: Mar 2009
Posts: 15
M
Mattie Offline OP
stranger
Mattie  Offline OP
stranger
M
Joined: Mar 2009
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.

Re: Strange (invalid??) PHP code [Re: Mattie] #223725
03/07/09 12:00 PM
03/07/09 12:00 PM
Joined: Apr 2007
Posts: 4,313
SoCal, USA
SD Offline
Carpal Tunnel
SD  Offline
Carpal Tunnel
Joined: Apr 2007
Posts: 4,313
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..

Re: Strange (invalid??) PHP code [Re: SD] #223728
03/07/09 12:36 PM
03/07/09 12:36 PM
Joined: Mar 2009
Posts: 15
M
Mattie Offline OP
stranger
Mattie  Offline OP
stranger
M
Joined: Mar 2009
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.

Re: Strange (invalid??) PHP code [Re: Mattie] #223729
03/07/09 12:51 PM
03/07/09 12:51 PM
Joined: Apr 2007
Posts: 4,313
SoCal, USA
SD Offline
Carpal Tunnel
SD  Offline
Carpal Tunnel
Joined: Apr 2007
Posts: 4,313
SoCal, USA
[Linked Image]

no problemo.. wink

Re: Strange (invalid??) PHP code [Re: SD] #223730
03/07/09 02:12 PM
03/07/09 02:12 PM
Joined: Dec 2003
Posts: 2,046
Texas
AllenAyres Offline
Pooh-Bah
AllenAyres  Offline
Pooh-Bah
Joined: Dec 2003
Posts: 2,046
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
Re: Strange (invalid??) PHP code [Re: AllenAyres] #223772
03/08/09 04:01 AM
03/08/09 04:01 AM
Joined: Mar 2009
Posts: 15
M
Mattie Offline OP
stranger
Mattie  Offline OP
stranger
M
Joined: Mar 2009
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


Shout Box
Today's Birthdays
No Birthdays
Recent Topics
Users Unable to Upload Avatar [Not a Bug]
by M4TT. 12/13/17 08:51 AM
Shout Box Sound Effect
by M4TT. 11/29/17 08:28 PM
Ad island
by TGCsanderson. 11/25/17 06:41 PM
Taking to long to connect to DB
by AstroCat. 11/24/17 12:34 PM
Forum Statistics
Forums36
Topics35,015
Posts190,544
Members12,045
Most Online978
Jun 24th, 2007
Random Image
Powered by UBB.threads™ PHP Forum Software 7.6.1
(Snapshot build 20171106)