PHP Chap 1 - 5 book questions

Ace your homework & exams now with Quizwiz!

What is the difference between $variable = 1 and $variable == 1?

$variable = 1 is an assignment statement, whereas the == in $variable == 1 is a comparison operator. Use $variable = 1 to set the value of $variable. Use $variable == 1 to find out later in the program whether $variable equals 1. If you mistakenly use $variable = 1 where you meant to do a com‐ parison, it will do two things you probably don't want: set $variable to 1 and return a true value all the time, no matter what its previous value was.

How is an object different from a function?

A function is a set of statements referenced by a name that can receive and return values. An object may contain zero or many functions (which are then called methods) as well as variables (which are called properties), all combined in a single unit.

What can a variable store?

A variable holds a value that can be a string, a number, or other data.

What four components (at the minimum) are needed to create a fully dynamic web page?

A web server (such as Apache), a server-side scripting language (PHP), a data‐ base (MySQL), and a client-side scripting language (JavaScript).

Which character must be placed at the end of every PHP statement?

All PHP statements must end with a semicolon (;).

What do the IP address 127.0.0.1 and the URL http://localhost have in common?

Both 127.0.0.1 and http://localhost are ways of referring to the local computer. When a WAMP or MAMP is properly configured, you can type either into a browser's address bar to call up the default page on the local server.

How many values can a function return?

By default, a function can return a single value. But by utilizing arrays, refer‐ ences, and global variables, it can return any number of values.

What does CSS stand for?

Cascading Style Sheets: styling and layout rules applied to the elements in an HTML document.

Why is it better to use a program editor instead of a plain-text editor?

Dedicated program editors are smart and can highlight problems in your code before you even run it.

Why is it a good idea to explicitly declare properties within a class?

Explicitly declaring properties within a class is unnecessary, as they will be implicitly declared upon first use. But it is considered good practice as it helps with code readability and debugging, and is especially useful to other people who may have to maintain your code.

What is the purpose of an FTP program?

FTP stands for File Transfer Protocol. An FTP program is used to transfer files back and forth between a client and a server.

Are the operators && and and interchangeable?

Generally, the operators && and and are interchangeable except where precedence is important, in which case && has a high precedence, while and has a low one.

What does HTML stand for?

HyperText Markup Language: the web page itself, including text and markup tags.

If you generate data within a function, what are a couple of ways to convey the data to the rest of the program?

If you generate data within a function, you can convey the data to the rest of the program by returning a value or modifying a global variable.

What actual underlying values are represented by TRUE and FALSE?

In PHP, TRUE represents the value 1, and FALSE represents NULL, which can be thought of as "nothing" and is output as the empty string.

Why do you suppose that an underscore is allowed in variable names ($current_user), whereas hyphens are not ($current-user)?

In PHP, the hyphen is reserved for the subtraction, decrement, and negation operators. A construct like $current-user would be harder to interpret if hyphens were also allowed in variable names, and in any case would lead pro‐ grams to be ambiguous.

Why is a framework such as jQuery Mobile so important for developing modern websites and web apps?

It allows developers to concentrate on building the core functionality of a web‐ site or web app, passing on to the framework the task of making sure it always looks and runs its best, regardless of the platform (whether Linux, macOS, Windows, iOS, or Android), the dimensions of the screen, or the browser it finds itself running on.

Name the main disadvantage of working on a remote web server.

It is necessary to FTP files to a remote server in order to update them, which can substantially increase development time if this action is carried out many times in a session.

Why does the name MySQL contain the letters SQL?

Like nearly all database engines, MySQL accepts commands in Structured Query Language (SQL). SQL is the way that every user (including a PHP pro-gram) communicates with MySQL.

Why is a for loop more powerful than a while loop?

Loops using for statements are more powerful than while loops because they support two additional parameters to control the loop handling.

How do if and while statements interpret conditional expressions of different data types?

Most conditional expressions in if and while statements are literals (or Boo‐ leans) and therefore trigger execution when they evaluate to TRUE. Numeric expressions trigger execution when they evaluate to a nonzero value. String expressions trigger execution when they evaluate to a nonempty string. A NULL value is evaluated as false and therefore does not trigger execution.

What is meant by operator associativity?

Operator associativity refers to the direction of processing (left to right, or right to left).

PHP and JavaScript are both programming languages that generate dynamic results for web pages. What is their main difference, and why would you use both of them?

PHP runs on the server, whereas JavaScript runs on the client. PHP can communicate with the database to store and retrieve data, but it can't alter the user's web page quickly and dynamically. JavaScript has the opposite benefits and drawbacks.

List three major new elements introduced in HTML5.

Probably the most interesting new elements in HTML5 are , , and , although there are many others, such as , , , and more.

What is the meaning of scope in PHP?

Scope refers to which parts of a program can access a variable. For example, a variable of global scope can be accessed by all parts of a PHP program.

If you encounter a bug (which is rare) in one of the open source tools, how do you think you could get it fixed?

Some of these technologies are controlled by companies that accept bug reports and fix the errors like any software company. But open source software also depends on a community, so your bug report may be handled by any user who understands the code well enough. You may someday fix bugs in an open source tool yourself.

What is the best way to force your own operator precedence?

The best way to force your own operator precedence is to place parentheses around subexpressions to which you wish to give high precedence.

What is the difference between unary, binary, and ternary operators?

The difference between unary, binary, and ternary operators is the number of operands each requires (one, two, and three, respectively).

What is the difference between the echo and print commands?

The echo and print commands are similar in that they are both constructs, except that print behaves like a PHP function and takes a single argument, while echo can take multiple arguments.

What is the purpose of functions?

The purpose of functions is to separate discrete sections of code into their own self-contained sections that can be referenced by a single function name.

What are the simplest two forms of expressions?

The simplest forms of expressions are literals (such as numbers and strings) and variables, which simply evaluate to themselves.

What tag is used to invoke PHP to start interpreting program code? And what is the short form of the tag?

The tag used is <?...?>. It can be shortened to , but that is not recommended practice.

Name the three conditional statement types

The three conditional statement types are if, switch, and the ?: operator

What is the difference between ++$j and $j++?

There is no difference between ++$j and $j++ unless the value of $j is being tested, assigned to another variable, or passed as a parameter to a function. In such cases, ++$j increments $j before the test or other operation is performed, whereas $j++ performs the operation and then increments $j.

How can you cause an object to be initialized when you create it?

To cause an object to be initialized when you create it, you can call a piece of initializing code by creating a constructor method called __construct within the class, and place your code there.

How do you convert one variable type to another (say, a string to a number)?

To convert one variable type to another, reference it and PHP will automatically convert it for you.

How do you create a new object in PHP?

To create a new object in PHP, use the new keyword like this: $object = new Class;

What syntax would you use to create a subclass from an existing one?

To create a subclass, use the extends keyword with syntax such as this: class Subclass extends Parentclass ...

How can you incorporate one PHP file within another?

To incorporate one file within another, you can use the include or require directives, or their safer variants, include_once and require_once.

What command can you use to skip the current iteration of a loop and move on to the next one?

To skip the current iteration of a loop and move on to the next one, use a continue statement.

What is the main benefit of using a function?

Using functions avoids the need to copy or rewrite similar code sections many times over by combining sets of statements so that they can be called by a sim‐ ple name.

What is the difference between a WAMP, a MAMP, and a LAMP?

WAMP stands for Windows, Apache, MySQL, and PHP. The M in MAMP stands for Mac instead of Windows, and the L in LAMP stands for Linux. They all refer to a complete solution for hosting dynamic web pages.

What is the result of combining a string with a number?

When you combine a string with a number, the result is another string.

What is the difference between accessing a variable by name and by reference?

When you reference a variable by name, such as by assigning its value to another variable or by passing its value to a function, its value is copied. The original does not change when the copy is changed. But if you reference a variable, only a pointer (or reference) to its value is used, so that a single value is referenced by more than one name. Changing the value of the reference will change the original as well.

Which symbol is used to preface all PHP variables?

With the exception of constants, all PHP variables must begin with $.

Are variable names case-sensitive?

Yes, variable names are case-sensitive. $This_Variable is not the same as $this_variable.

How can you make a variable accessible to all parts of a PHP program?

You can make a variable accessible to all parts of a PHP program by declaring it as global.

What are the two types of comment tags?

You can use // for a single-line comment or /*...*/ to span multiple lines.

How do you escape a quotation mark?

You can use \' or \" to escape either a single or double quote.

How can you create a multiline echo or assignment?

You can use multiple lines within quotations marks or the <<<_END..._END; construct to create a multiline echo or assignment. In the latter case, the closing tag must be on a line by itself with nothing before or after it.

Can you redefine a constant?

You cannot redefine constants because, by definition, once defined they retain their value until the program terminates.

Can you use spaces in variable names?

You cannot use spaces in variable names, as this would confuse the PHP parser. Instead, try using the _ (underscore).

When would you use the === (identity) operator?

You use the identity operator when you wish to bypass PHP's automatic operand type changing (also called type casting).


Related study sets

Biology 210 Chapter 12 Cardiovascular system

View Set

Chapter 33. Nursing Care of Patients With Upper Gastrointestinal Disorders

View Set

Exam #3- Movement/era and culture and Art Name/ Artist

View Set

adaptive quizzing chapter 12 central nervous system

View Set

Psychology chapter 2 multiple choice

View Set