141⟩ Are objects in PHP 5 passed by value or reference?
This is basically a trick questions. To understand how they are passed you need to understand how objects are instantiated.
“Sr. PHP Programmer based Frequently Asked Questions by expert members with experience as Senior PHP Programmer. These questions and answers will help you strengthen your technical skills, prepare for the new job test and quickly revise the concepts”
This is basically a trick questions. To understand how they are passed you need to understand how objects are instantiated.
They are both variables. But $var is a variable with a fixed name. $$var is a variable who's name is stored in $var. For example, if $var contains "message", $$var is the same as $message.
Using getCode() method of Exception class which returns the code of exception.
$_COOKIE − An associative array of variables passed to the current script via HTTP cookies.
Using getLine() method of Exception class which returns source line.
The strlen() function is used to find the length of a string. Let's find the length of our string "Hello world!" −
<?php
echo strlen("Hello world!");
?>
This will produce following result −
12
'&' indicates a reference
eregi() − The eregi() function searches throughout a string specified by pattern for a string specified by string. The search is not case sensitive.
A PHP session cookie is set in the clients browser, on every request the client sends that cookie to the server. PHP then uses that cookie to select the corresponding session information. By default PHP session_start() will store session data in files, you can also store sessions in a database.
$_SERVER − This is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these. See next section for a complete list of all the SERVER variables.
they both include a specific file but on require the process exits with a fatal error if the file can't be included, while include statement may still pass and jump to the next step in the execution.
Using $_FILES['file']['type'] − it provides the MIME type of the uploaded file.
Don't get scared by the big word. It's simply the idea that one object can can take on many forms. So in PHP OOP one class "cars" may have two classes that extend it, for example a "Honda" class and a "BMW" class.
Using $_FILES['file']['tmp_name'] − it provides access to the uploaded file in the temporary directory on the web server.
"::" double colons is the scope operator it is used to call methods of a class that has not been instantiated. You should also understand static methods and how they differ from regular methods.
$_PHP_SELF − A string containing PHP script file name in which it is called.
PHP has a total of eight data types which we use to construct our variables −
☛ Integers − are whole numbers, without a decimal point, like 4195.
☛ Doubles − are floating-point numbers, like 3.14159 or 49.1.
☛ Booleans − have only two possible values either true or false.
☛ NULL − is a special type that only has one value: NULL.
☛ Strings − are sequences of characters, like 'PHP supports string operations.'
☛ Arrays − are named and indexed collections of other values.
☛ Objects − are instances of programmer-defined classes, which can package up both other kinds of values and functions that are specific to the class.
☛ Resources − are special variables that hold references to resources external to PHP (such as database connections).
☛ Private - Visible only in its own class
☛ Public - Visible to any other code accessing the class
☛ Protected - Visible only to classes parent(s) and classes that extend the current class
This is important for any developer to know because it shows an understanding that building applications is more than just being able to write code. One must also have an understanding about privileges and accessibility of that code. There are times protected variables or methods are extremely important, and an understanding of scope is needed to protect the integrity of the data in your application along with provide a clear path through the code.
$php_errormsg − $php_errormsg is a variable containing the text of the last error message generated by PHP.
ereg() − The ereg() function searches a string specified by string for a string specified by pattern, returning true if the pattern is found, and false otherwise.