PHP Set 1 Flashcards

1
Q

What are the steps for a web server processing a request that includes PHP?

A
  1. The web server receives a request from a client
  2. The web server recognizes the HTML document requested contains PHP code
  3. The server executes the PHP code, substitutes its output into the HTML document
  4. The resulting page is sent to the client
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the two methods used to output in PHP?

A

echo and print

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

Do print and echo require parentheses to work?

A

No, you could do
echo “hello, world”
and it would work

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

What are the 8 datatypes that were included in PHP before version 8?

A

Primitive types
1. bool for booleans
2. int for integers
3. float for floating point numbers
4. string for strings
Compound types
1. array
2. object
Special types
1. resource
2. NULL

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

What is the difference in output for the strings ‘glass\table’ and “glass\table”?

A

‘glass\table’ outputs glass\table
“glass\table” outputs
glass able
because \t is the tab character

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

What are the 3 types of arrays in PHP?

A
  1. Indexed arrays which are arrays with a numeric index
  2. Associative arrays which are arrays with named keys like a dictionary
  3. Multidimensional arrays which are arrays that contain one or more arrays
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the object type?

A

A data type which stores not only data but also information on how to process the data

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

What is the difference between converting from object to object and from array to object?

A

objects converted to other objects are not modified
When an array is converted to an object it will have properties named by keys and their corresponding values. For other values, a member variable named scalar will contain the value

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

What is the syntax for converting an array to an object?

A

$object = (object) $array;

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

What is the resource type?

A

A special data type that refers to an external resource. These resources are created and used by special functions

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

What is the NULL type?

A

Represents a variable with no value. null is the only possible value of type null

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

When is a variable considered to be null?

A
  1. It has been assigned the constant null
  2. It has not yet been set to any value
  3. It has been unset()

Empty arrays are considered to be null

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

What are the constants NAN and INF used for?

A

They are used as return values for some applications of mathematical functions that do not return a number.

For example log(0) will return -INF and sqrt(-1) will return NAN

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

What values of other types are considered false when converted to boolean?

A
  1. The boolean FALSE
  2. The integer 0
  3. The float 0.0
  4. The string ‘0’ but not ‘0.0’ or ‘00’
  5. The empty string “”

All other values are TRUE including any resource

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

What happens when you convert a boolean to a string?

A

TRUE becomes “1”
FALSE becomes “”

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

What are the rules for using variables in PHP?

A
  1. Variable names cannot start with a digit but they can contain digits, letters, and underscores
  2. A variable does not have to be declared before it can be used
  3. A variable does not have to be initialized before it is used but it is typically a good idea
17
Q

What are the default values of uninitialized variables?

A
  1. bool: FALSE
  2. int/float: 0
  3. string: “”
  4. array: empty array
18
Q

How do you create a constant in PHP?

A

Using the keywork “define” allows you to define a constant or an array of constants

Ex: define(“ANIMALS”, [“cat”, “dog”]);