PHP Questions
PHP questions suitable for use in interviews or just for fun.
PHP Question: While And Do While Looping
Question
What does the $count variable equal after each of these loops?
PHP Question: Defining Constants
Question
What does the following code do?
PHP Question: Class Methods
Question
What is the difference between these two lines of code and can you produce the background code used for them?
PHP Question: PHP Script Shape
Question
Write a PHP script that will print out the following text in the correct diamond shape.
PHP Question: Print Object
Question
The following code was executed.
<?php class MyClass { private $foo = "bar"; } $myObject = new MyClass(); echo $myObject;
Which produced the following error.
Catchable fatal error: Object of class MyClass could not be converted to string in test.php on line 7 Call Stack: 0.0011 323736 1. {main}() /test.php:0
How can the code be simply changed to prevent this error and produce some form of result?
PHP Question: Object Property Increment
Question
What does the following snippet print and why?
PHP Question: Form Variables
Question
Given the following form:
<form method="post" action="index.php"> <input type="input" value="" name="text" /> <input type="submit" value="Submit" /> </form>
How would you get hold of the value of the input box after the form is submitted?
PHP Question: Pass By Reference
Question
Consider the following:
function doSomething(&$val) { $val++; } $a = 1; doSomething($a);
What does the variable $a now equal?
PHP Question: Variable Reference
Question
What does the following code snipped print?
$a = 5; $b = 'a'; print $$b;