0

So I'm learning PHP, well I'm learning more complex standards of php as per phpfox. An issue I'm having is with a few lines of code - I get what they 'do'. But I don't understand why they are structured that way. Could someone explain?

In the following line of code the if statements are cornered by {} and not in the usual:

if thing('condition') {
do stuff
}

Way that i'm familiar with. Why is this?

{if Phpfox::isUser() && !PHPFOX_IS_AJAX && $sCustomViewType === null}
{if (Phpfox::getUserBy('profile_page_id') > 0 && defined('PHPFOX_IS_USER_PROFILE')) 
|| (isset($aFeedCallback.disable_share) && $aFeedCallback.disable_share) 
|| (defined('PHPFOX_IS_USER_PROFILE') && !Phpfox::getService('user.privacy')->hasAccess('' . $aUser.user_id . '', 'feed.share_on_wall'))
|| (defined('PHPFOX_IS_USER_PROFILE') && !Phpfox::getUserParam('profile.can_post_comment_on_profile'))
}

{else}

Also what is the :: thing about? and when I see (not in this) a | by itself, what is that doing?

Thanks very much for any help :)

user1368968
  • 107
  • 1
  • 5
  • possible duplicate of [Reference - What does this symbol mean in PHP?](http://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-php) – NikiC Jun 09 '12 at 11:57
  • My guess is that the kooky PHP syntax could be a templating language of some sort, though I don't recognise it. You should also look at [the scope resolution operator `::`](http://php.net/manual/en/language.oop5.paamayim-nekudotayim.php) and [the bitwise OR operator `|`](http://php.net/manual/en/language.operators.bitwise.php). – lonesomeday Jun 09 '12 at 11:57
  • This seems to be a part of a smarty template file and phpfox uses smarty afaik. so that has to be it. – avk Jun 09 '12 at 12:03

4 Answers4

3

That code does nothing. (Literally, it only checks stuff and does nothing with it).

Don't code that way.


As for the ::, that's called the Scope Resolution Operator, it's used to mark static class variables, static class methods and class constants.

The single pipe (|) is the Bitwise OR Operator.

Madara's Ghost
  • 158,961
  • 49
  • 244
  • 292
  • thanks for all the info people :) I'll look into smarty templates as well - I thought the fact that it checked stuff irrelevantly was pointless. Man stack overflow is so great for learning things. You guys always come through with such great info. – user1368968 Jun 09 '12 at 22:32
1

Well, it seems like this is not exactly PHP only. it is a part of a smarty template and this is how we use if else in a smarty template file.

example from smarty site itself.

{if $name eq 'Fred'}
    Welcome Sir.
{elseif $name eq 'Wilma'}
    Welcome Ma'am.
{else}
    Welcome, whatever you are.
{/if}

more details on this link http://www.smarty.net/docsv2/en/language.function.if.tpl

DO correct me if i am wrong.

avk
  • 994
  • 6
  • 13
0

Looks like phpfox templates (uses smarty).

http://www.phpfox.com/kb/article/231/template-tags-in-phpfox/

So the part between the {if} and the {else} which you probably left out, is what gets generated (to html) if the condition in the if is true.

The :: thing is the call of a static method. Phpfox is a class with a static method. Those methods do not need a object and are called ClassName::method()

Stefan
  • 1,061
  • 7
  • 7
0

You can used if else condition easily in smarty template page . example from smarty site itself.

{if $name=='anil'} anil gupta {else} amita gupta {/if}