Which PHP function is used to start a new session or to resume an existing session?
- session_start()
- start_session()
- begin_session()
- resume_session()
The session_start() function in PHP is used to start a new session or resume an existing session. It initializes session variables and allows you to work with user-specific data across multiple pages.
In PDO, which method is used to bind a value to a named placeholder in a prepared statement?
- bindParam()
- bindValue()
- execute()
- prepare()
The correct method in PDO to bind a value to a named placeholder is bindValue(). It allows for precise data binding and is commonly used in prepared statements.
The ________ operator in PHP is used to check if two values are not equal.
- != (Not Equal)
- == (Equal)
- >= (Greater Than or Equal)
- !== (Identically Not Equal)
In PHP, the '!=' operator checks for inequality between two values. It returns true if the values are not equal.
In PHP, which keyword is used to define a constant?
- constant
- define
- const
- let
Constants in PHP are defined using the define function. It's not a keyword but a function used to create named constants with a specific value.
You are building a web application where the security of user data is paramount. Which password hashing algorithm would be most appropriate to use in PHP?
- password_hash()
- md5()
- sha1()
- bcrypt()
bcrypt() is the recommended choice for secure password hashing in PHP. It's a one-way hashing algorithm with salting, making it extremely resistant to brute-force and rainbow table attacks. In contrast, md5() and sha1() are outdated and less secure. password_hash() is a more recent option, but it's best used with bcrypt().
A variable that starts with a number in PHP will result in a ________.
- Syntax Error
- Warning
- Notice
- No Error
In PHP, a variable that starts with a number will result in a Syntax Error. Variable names must start with a letter or underscore in PHP.
In a multidimensional array, how would you access the second element of the first array?
- $array[0][1]
- $array[1][0]
- $array[2][1]
- $array[0][2]
In a multidimensional array, you access elements by specifying the indices for each dimension. To access the second element of the first array, you would use $array[0][1], where 0 represents the first array and 1 represents the second element within that array.
Which of the following is a predefined function in PHP used to get the length of a string?
- str_length()
- strlen()
- string_length()
- lengthOfString()
The 'strlen()' function in PHP is used to find the length of a string, counting the number of characters in the string. It's a commonly used function for string manipulation.
When a child class inherits from a parent class, it can also be referred to as a ________ relationship.
- Inheritance
- Association
- Aggregation
- Composition
In object-oriented programming, when a child class inherits from a parent class, it forms an inheritance relationship, inheriting properties and methods.
Which of the following PHP functions is commonly used to create a hashed password?
- encrypt()
- hash_password()
- password_hash()
- create_hashed_password()
The password_hash() function in PHP is commonly used for creating hashed passwords. It incorporates strong encryption algorithms and automatically generates a unique salt for each password, enhancing security.