PHP Basics Flashcards

1
Q

What are the different opening and closing tags for PHP?

A

{?php //standard tags, always available ?}

{? //short open tags (need short_open_tag enabled in php.ini, or configured with –enable-short-tags option)

{?= ?}//short echo tags (enabled by default since php 5.4, regardless of short_open_tag php.ini setting, equal to {?php echo …})

{% %}, {%= //asp tags (need asp_tags enabled in php.ini) //case insensitive, always available

script tag: {script language=”php”}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How should large blocks of text be outputted in PHP?

A

By dropping out of parsing mode. It’s generally more efficient than sending all of the text through echo or print.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What opening and closing tags should you use if you are embedding PHP within HMTL or XHTML?

A

The standard tags must be used to remain compliant with standards.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why are short opening and closing PHP tags not recommended?

A

They’re not as portable, because they may not be supported on the target server.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Can the {?php opening tag be the only thing in a file?

A

Yes, provided there are one or more whitespace characters after the opening tag.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Do you need a semicolon terminating the last line of a PHP block?

A

No. The closing tag of a block automatically implies a semicolon.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Does a closing tag for a block include an immediately trailing newline?

A

Yes, if one is present.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the advantages of omitting the PHP closing tag?

A

-When using include or require, so unwanted whitespace will not occur at the end of files, and you will still be able to add headers to the response later.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What type of comments does PHP support?

A
  • One-line C++ style: //
  • Multi-line C style: /* */
  • Unix shell style: #
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

When do one-line comment styles terminate?

A

At the end of the line or the current block of PHP code, whichever comes first. The one exception is {script} tags, which do not break out of PHP mode in a one-line comment.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Can you nest C-style comments?

A

No.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly