Jump to content

Newbie Question on Syntax


vincej

Recommended Posts

I often see the colon ( : ) being used in syntax however, no amount of searching through my text books or checking php.net reveals to me exactly what this is used for, when it is used and the exact definition of it's value.

 

Intuitively it seems to mean ' or '  but I can't be sure when || is the proper operator for 'or'

 

Can anyone point me towards a url for a succinct explanation ?

 

thanks VJ

Link to comment
Share on other sites

If you're talking about something like

echo isset($_POST['text']) ? "Field is {$_POST['text']}" : 'Field is not set';

 

That is ternary syntax, and is essentially shorthand for

if( isset($_POST['text']) ) {
     echo "Field is {$_POST['text']}";
} else {
     echo 'Field is not set';
}

 

More about it can be found on this page.

Link to comment
Share on other sites

well I see it in VirtueMart a lot - I still don't get what it means , eg

 

<?php echo ps_product::image_tag( $product_thumb_image, 'class="browseProductImage" border="0" title="'.$product_name.'" alt="'.$product_name .'"' ) ?></a>

 

 

OR /

 

 

<td nowrap="nowrap" width="10%" align="right"><?php echo $VM_LANG->_('PHPSHOP_ORDER_PRINT_COMPANY') ?>: </td>

 

 

 

 

 

 

 

Link to comment
Share on other sites

well I see it in VirtueMart a lot - I still don't get what it means , eg

 

<?php echo ps_product::image_tag( $product_thumb_image, 'class="browseProductImage" border="0" title="'.$product_name.'" alt="'.$product_name .'"' ) ?>

That is a static method call, ps_product is the class and image_tag() is the method.  Similar to an object method $object->method() except acting on a class staically instead of on an instance of the class.  Read up on OOP in the PHP manual:  http://us2.php.net/manual/en/language.oop5.php

 

<td nowrap="nowrap" width="10%" align="right"><?php echo $VM_LANG->_('PHPSHOP_ORDER_PRINT_COMPANY') ?>: </td>

That is just a : in the HTML, notice it isn't inside the PHP tags.

Link to comment
Share on other sites

Well, this one here is pretty complicated . . .

<td nowrap="nowrap" width="10%" align="right"><?php echo $VM_LANG->_('PHPSHOP_ORDER_PRINT_COMPANY') ?>: </td>

 

It actually causes a colon to be echoed to the screen, like this :

 

:P

 

EDIT: Dang. AC beat me to this one.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.