Lecture
Thorough preparation is one of the key elements of passing an interview successfully, and, incidentally, it is often neglected.
Although this article does not claim to be objective, it covers all the main questions that may be asked on PHP, JS, jQuery, CSS, HTML, MySQL and OOP, along with detailed answers to them.
By studying these topics, you will noticeably improve your theoretical foundation and significantly increase your chances of landing the coveted job.
PHP supports 8 basic data types.
4 scalar types:
— boolean. A logical data type; variables of this type can take the value true or false.
— integer. An integer data type; variables can take whole values (…-2, -1, 0, 1, 2…) in the range from -2^31 to +2^31. If a value exceeds this limit, it is automatically converted to the float type.
— float. A floating-point numeric data type that can hold both whole and fractional values.
— string. A string data type. It contains a non-fixed number of various characters. PHP imposes no limit on string length, so you can safely work even with VERY large strings.
2 compound types:
— array. An array, which contains an ordered list of elements.
— object. An object, which holds some object (an instance of a class).
2 special types:
— resource. A reference to an abstract element, the so-called external resource. Examples of external resources are a file handle and a query result reference.
— NULL. An empty data type denoting the absence of any value. Such values are usually described as "undefined". Variables of any other type can be initialized with the empty value.
A static member belongs to the class, not to an instance of the class. It is called on the class, not on an object, i.e. directly. Declaring class properties and methods as static allows you to access them without creating an instance of the class. A class attribute declared static cannot be accessed through an instance of the class (but a static method can be called). Since static methods are called without creating an instance of the class, the pseudo-variable $this is not available inside a method declared static. Static class properties cannot be accessed through the -> operator.
In double quotes the data is "parsed", while in single quotes it is not. In this case, with double quotes Chimay will be output, and with single quotes — $beer.
|
1 2 |
$beer = 'Chimay'; echo "$beer"; |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$lst = array(); $k = "prime";
for ($i = 2; $i < 100; $i++) { for ($j = 2; $j < $i; $j++) { if (($i % $j) == 0) { $k = "not prime"; } }
if ($k == "prime") $lst[] = $i; else $k = "prime"; }
foreach($lst as $list) echo $list . ""; |
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
$find = array( ‘fuck’, ‘idiot’, ‘bitch’ ); $replace = array( ‘f * *k’, ‘id * *t’, ‘bi * *h’ ); If (isset($_POST[‘user_input’]) && !empty($_POST[‘user_input’])) { $user_input = $_POST[‘user_input’]; $user_input_new = str_ireplace($find, $replace, $user_input); echo $user_input_new; } |
A dynamic variable is one whose name is stored in another variable. This is the so-called "variable variable". For example:
|
1 2 3 |
$var = "first"; $$var = "Second"; // $$var == $first == "Second" |
$$var is dynamic; its name can change along with $var. You can also bind a variable name to the contents of another variable implicitly:
|
1 2 3 4 |
$first = "second"; $second = "third"; print $first; // prints "second" print $$first; // prints "third" |
A design pattern is a general, typical solution to a problem that recurs repeatedly when designing the architecture of a software product. Patterns show the relationships and interactions between classes and make a system flexible and easy to change. Their proper use increases the reuse rate of ready-made solutions.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
Class One { function foo() { echo “Hellofromclass One!”; }
function callMe() { $this->foo(); } }
Class Two extends One { function foo() { echo “Hellofromclass Two”;
} }
$Two = new two(); $Two->callMe(); |
The most common ones are functional, aspect-oriented and procedural.
Like this:
|
1 |
setTimeout(alert(“Hello”), 3000); |
Or like this:
|
1 |
setTimeout(function() {alert(“Hello”)}, 3000); |
Objects (also known as associative arrays or hashes) and working with them in JavaScript are implemented differently than in most languages. An object in JavaScript is an ordinary associative array or, in other words, a "hash". It stores any "key => value" mappings and has several standard methods.
|
1 |
function f(a,b) { return a+b } |
and
|
1 |
var f = function(a,b) { return a+b } |
There is a difference, and it lies in the visibility of the function. The variant without var is visible everywhere in the current scope, including before the function's definition. The variant with var assigns the function to a variable, so such a function is visible only after the definition.
It will exit the current loop or switch block to the label "me_baby".
SQL injection is the embedding of malicious code into database queries. Using SQL injection, an attacker can not only obtain private information from the database but, under certain conditions, also modify it. Vulnerability to SQL injection arises because user input gets into a database query without proper processing: to keep a script from being vulnerable, you need to make sure that all user data enters all database queries in escaped form.
|
1 2 3 |
SELECT customer_name, SUM(order_price) FROM orders GROUP BY customer_name; |
#my is an ID selector.
.my is a class selector.
Pseudo-classes are what is usually written after a selector, separated by a colon, to define a reaction or state for that selector. The best-known pseudo-classes are :link, :hover, :visited and :active. Pseudo-classes have the following structure:
|
1 2 3 |
selector:pseudo class { property: value; } |
i.e. you only need to put a colon between the selector and the pseudo-class.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
a.snowman:link { color: blue; } a.snowman:visited { color: purple; } a.snowman:active { color: red; } a.snowman:hover { text-decoration: none; color: blue; background-color: yellow; } |
|
1 |
$(“div.one”).add(“p.two”).addClass(“three”).slideDown(“slow”); |
|
1 |
$(‘div:not(.cls)’); |
DOCTYPE is a document type declaration (Document Type Definition (DTD)), the rules against which a particular XML or (X)HTML document (web page) is validated. Thanks to this declaration, the browser determines which DTD version the document uses. It is needed so that browsers render the document markup correctly. If no DOCTYPE is specified, the browser will add its own "improvisation", and each browser will add its own. As a result, there can be no talk of any cross-browser compatibility.
Entities are combinations of the & sign followed by an alphabetic or numeric code, intended to stand in for characters that cannot appear in "plain" form in HTML text, for example the "<" character.
These are methods reserved in PHP that begin with a double underscore "__".
List of all magic methods:
__construct and __destruct are the most popular methods, which implement basic concepts of object-oriented programming: the constructor and the destructor;
__call, __callStatic, __get and __set are methods related to overloading access to both properties
and methods. The __get() and __set() methods are called when a property value is read or set,
and the __call() and __callStatic methods are called when a method is invoked. Note that these magic functions
will be called only and exclusively when the requested method or property
does not exist;
__isset is a method triggered when the empty() or isset() functions are called on a nonexistent
or inaccessible class property;
__unset is triggered when the unset() function is called on a nonexistent or inaccessible class property;
__sleep and __wakeup are methods called only from the serialize and unserialize functions,
respectively. The __sleep method is called immediately when the serialize function is applied to an object, and
the __wakeup method when unserialize is applied. Currently these methods are used to save the current state of the system with subsequent restoration of that state
(for example, a database connection);
__toString is a method that lets you treat a class as a string (for example, with
print or echo);
__set_state is a method called for classes exported by the var_export()
function, to export property values;
__clone is called when an object is cloned (introduced because objects
in PHP 5 and above are passed by reference);
__invoke is called when an attempt is made to use an object as a function.
Comments