1.
PHP is client sided.
Correct Answer
B. False
Explanation
The given statement is incorrect. PHP is a server-side scripting language, not a client-sided one. It is primarily used for generating dynamic web pages and handling server-side tasks such as interacting with databases, processing form data, and generating HTML content to be sent to the client's browser. The client-side refers to the execution of code on the user's browser, which is typically done using languages like JavaScript. Therefore, the correct answer is False.
2.
Which data can you track with PHP only? Choose all options that apply.
Correct Answer(s)
B. IP adress
C. User agent
D. Refferal url
Explanation
With PHP, you can track the IP address of the user visiting your website. The IP address can provide information about the user's location and can be used for various purposes such as tracking user activity or implementing security measures. Additionally, PHP can also track the user agent, which refers to the web browser and operating system being used by the visitor. This information can be helpful for optimizing the website's design and functionality. Lastly, PHP can track the referral URL, which indicates the website or page from which the user originated before landing on your site. This can be useful for analyzing traffic sources and understanding user behavior. However, PHP cannot directly track the MAC address or screen resolution of the user's device.
3.
You can execute Linux commands with php on a Linux based server.
Correct Answer
A. True
Explanation
This statement is true because PHP is a server-side scripting language that can be used to execute commands on a Linux based server. PHP has built-in functions and libraries that allow developers to interact with the operating system and execute Linux commands. This capability is particularly useful for tasks such as file manipulation, system administration, and server management. Therefore, it is possible to execute Linux commands using PHP on a Linux based server.
4.
(int) $i = 1;
(int) $j = 2;
list($i,$j) = array($j,$i);
echo $i;
What will be the output?
Correct Answer
B. 2
Explanation
The code initializes two variables, $i with the value of 1 and $j with the value of 2. Then, it uses the list() function to assign the values of $j and $i to $i and $j respectively, effectively swapping their values. Finally, it echoes the value of $i, which is now 2. Therefore, the output will be 2.
5.
class Animal {
public function makeNoise() {
echo 'Some kind of noise';
}
}
class Cat extends Animal {
public function makeNoise() {
echo 'Meow';
}
}
$cat = new Cat();
$cat->makeNoise();
What will be the output?
Correct Answer
B. Meow
Explanation
The output will be "Meow" because the makeNoise() method in the Cat class overrides the makeNoise() method in the Animal class. When the makeNoise() method is called on the $cat object, it will execute the makeNoise() method in the Cat class, which echoes "Meow".
6.
class Animal {
public final function makeNoise() {
echo 'Some kind of noise';
}
}
class Cat extends Animal {
public function makeNoise() {
echo 'Meow';
}
}
$cat = new Cat();
$cat->makeNoise();
What will be the output?
Correct Answer
C. This will give an error
Explanation
The given code will give an error. This is because the makeNoise() function in the Animal class is declared as final, which means it cannot be overridden in the child class. However, in the Cat class, the makeNoise() function is trying to override the function in the parent class. Since it is not allowed, an error will occur.
7.
Check the ones that are incorrect.
Correct Answer(s)
A. $1var;
D. $var-iable;
E. $variäble;
Explanation
The question asks to identify the incorrect variables among the given options. The correct answer is "$1var;,$var-iable;,$variäble;". This is because variable names cannot start with a number or contain special characters like hyphens or umlauts. Therefore, "$1var;", "$var-iable;", and "$variäble;" are all invalid variable names.
8.
$string = null;
if($string === '') {
echo 'It works!';
}
What will be the output?
Correct Answer
B. There won't be an output!
Explanation
The code checks if the variable $string is identical to an empty string. However, the variable $string is set to null, not an empty string. Therefore, the condition will not be true and the code inside the if statement will not be executed. As a result, there won't be any output.
9.
class Animal {
private $noise = 'Some kind of noise';
public function makeNoise() {
echo self::$noise . ' ; woof woof';
}
}
$animal = new Animal();
$animal->makeNoise();
What will be the output?
Correct Answer
D. This will give an error
10.
How do you browse through an array?
Correct Answer
B. Foreach($array as $key => $value) {}
Explanation
The correct answer is "foreach($array as $key => $value) {}". This is because the foreach loop is specifically designed for iterating over arrays. It allows you to access each element of the array one by one, assigning the key and value of each element to variables ($key and $value in this case). This loop structure is commonly used for looping through arrays and performing operations on each element.
11.
You can make images with php.
Correct Answer
A. True
Explanation
PHP is a server-side scripting language that can generate dynamic content. It has built-in functions and libraries that allow developers to create and manipulate images. With PHP, you can create, edit, and manipulate images by using various functions and libraries like GD or ImageMagick. Therefore, the statement "You can make images with PHP" is true.
12.
You can decrypt a string made by the md5() method.
Correct Answer
B. False
Explanation
The statement is false because the md5() method is a one-way hash function, which means it is designed to be irreversible. It is used for generating a unique hash value for a given input string, but it cannot be decrypted to obtain the original string. Therefore, it is not possible to decrypt a string made by the md5() method.
13.
You can make a zip with php.
Correct Answer
A. True
Explanation
In PHP, the "zip" extension allows you to create, open, and extract files from ZIP archives. This extension provides functions to create a new ZIP file, add files to an existing ZIP file, and extract files from a ZIP file. Therefore, it is possible to make a zip with PHP, making the answer "True" correct.
14.
What is a constructor if you are talking about object orientated programming?
Correct Answer
B. A pre-defined name of a function that is as first called when initializing an object of that class.
Explanation
A constructor is a pre-defined name of a function that is called first when initializing an object of a class in object-oriented programming. It is responsible for initializing the object's state and performing any necessary setup tasks.
15.
Is the function preg_replace() or a similar one required to make ubb code?
Correct Answer
B. No
Explanation
No, the function preg_replace() or a similar one is not required to make UBB code. UBB code is a simple text formatting language that uses tags enclosed in square brackets to format text. It can be implemented using basic string manipulation functions like str_replace() or even with regular expressions. The preg_replace() function is commonly used for more complex pattern matching and replacement tasks, but it is not necessary for basic UBB code implementation.