Editing
PHP Skills Tests
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Language constructs == === Is `print()` a function? === `print()` is a language construct. <ref>[http://php.net/manual/en/function.print.php print()], PHP documentation</ref> <syntaxhighlight lang="php"> echo ((function_exists("print"))?("y"):("n")); /* <<< output is "n" */ echo ((function_exists("printf"))?("y"):("n")); /* <<< output is "y" */ echo ((function_exists("echo"))?("y"):("n")); /* <<< output is "n" */ </syntaxhighlight> * Both `echo` and `print` are constructs, not functions. This makes parentheses deceiving. * Both `echo` and `print` will output everything that follows to the right. * `echo` does not return a value. * `print` ''always'' returns `1`, never the value to the right of it. * Also, the string concatenation operator (`.`) has high precedence in PHP. But that's a red herring in the following example. <syntaxhighlight lang="php"> echo '1'.print(2)+3; // result: 511 /** * `echo` in this example prints everything that comes after it. It's necessary to evaluate everything to the right of 'echo' first. * `print` also outputs everything to the right, regardless of parentheses. * (1) Add (2) + 3 results in the value 5 * (2) print 5 outputs 5 to stdout, and returns the value `1`. * (3) Concatenate '1' with the return value of 'print' results in "11" * (4) 'echo' the output after what's already been sent to stdout, so "11" follows the "5". */ </syntaxhighlight> === Control structure alternative syntax === '''Q: Is the following code valid?''' <syntaxhighlight lang="php"> $a = 5; if ($a==5): echo "Hello"; echo "1"; else: echo "Not hello"; echo "2"; endif; </syntaxhighlight> '''A: Yes''' === Grouping operators === '''Q: What is empty `()`?''' <ol style="list-style-type=lower-latin;"> <li>A function</li> <li>A language construct</li> <li>A variable</li> <li>A reference</li> <li>None of the above</li> </ol> ''My first guess was (b) a language construct. After more considerations maybe it's more likely (e) None of the above?'' They are grouping operators, or delimiting expressions. I have never seen them used without something inside. Maybe the answer is "e". The question isn't clear about the context. I guess on their own they are meaningless. === Gettext === '''Q: Can PHP use Gettext?''' <ol style="list-style-type=lower-latin;"> <li>yes</li> <li>no</li> </ol> I don't even know what this means, or what it's getting at. There is a [http://php.net/manual/en/book.gettext.php documentation page for `gettext`] which says, "The gettext functions implement an NLS (Native Language Support) API which can be used to internationalize your PHP applications." Which implies that PHP can use Gettext? Support is specific to the implementation, but there are gettext functions. No one offered an answer at [http://hlam.com.ua/expertrating/question.php?id=12925 this cheater's site].
Summary:
Please note that all contributions to Littledamien Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Littledamien Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information