gmnon.cn-疯狂蹂躏欧美一区二区精品,欧美精品久久久久a,高清在线视频日韩欧美,日韩免费av一区二区

站長資訊網(wǎng)
最全最豐富的資訊網(wǎng)站

45 個(gè)必知必會(huì)的 PHP 面試題

本篇文章給大家總結(jié)了45 個(gè)必知必會(huì)的 PHP 面試題 。有一定的參考價(jià)值,有需要的朋友可以參考一下,希望對(duì)大家有所幫助。

45 個(gè)必知必會(huì)的 PHP 面試題

php零基礎(chǔ)到就業(yè)直播視頻課:進(jìn)入學(xué)習(xí)
程序員必備接口測(cè)試調(diào)試工具:立即使用

Q1: == 和 === 之間有什么區(qū)別?#

話題: PHP
困難: ⭐

  • 如果是兩個(gè)不同的類型,運(yùn)算符 == 則在兩個(gè)不同的類型之間進(jìn)行強(qiáng)制轉(zhuǎn)換
  • === 操作符執(zhí)行’類型安全比較

這意味著只有當(dāng)兩個(gè)操作數(shù)具有相同的類型和相同的值時(shí),它才會(huì)返回 TRUE。

1 === 1: true 1 == 1: true 1 === "1": false // 1 是一個(gè)整數(shù), "1" 是一個(gè)字符串 1 == "1": true // "1" 強(qiáng)制轉(zhuǎn)換為整數(shù),即1 "foo" === "foo": true // 這兩個(gè)操作數(shù)都是字符串,并且具有相同的值

? 源自: stackoverflow.com

Q2: 如何通過引用傳遞變量?#

話題: PHP
困難: ⭐

為了能夠通過引用傳遞變量,我們?cè)谄淝懊媸褂?&,如下所示:

$var1 = &$var2

? 源自: guru99.com

Q3: $GLOBAL 是什么意思?#

話題: PHP
困難: ⭐

$GLOBALS 是關(guān)聯(lián)數(shù)組,包含對(duì)腳本全局范圍內(nèi)當(dāng)前定義的所有變量的引用。

? 源自: guru99.com

Q4: ini_set () 有什么用處?#

話題: PHP
困難: ⭐

PHP 允許用戶使用 ini_set () 修改 php.ini 中提到的一些設(shè)置。此函數(shù)需要兩個(gè)字符串參數(shù)。第一個(gè)是要修改的設(shè)置的名稱,第二個(gè)是要分配給它的新值。

給定的代碼行將啟用腳本的 display_error 設(shè)置 (如果它被禁用)。

ini_set('display_errors', '1');

我們需要將上面的語句放在腳本的頂部,以便該設(shè)置一直保持啟用狀態(tài),直到最后。此外,通過 ini_set () 設(shè)置的值僅適用于當(dāng)前腳本。此后,PHP 將開始使用 php.ini 中的原始值。

? 源自: github.com/Bootsity

Q5: 我應(yīng)該在什么時(shí)候使用 require 和 include 呢?#

話題: PHP
困難: ⭐⭐

require() 函數(shù)與 include() 函數(shù)相同,只是它處理錯(cuò)誤的方式不同。如果出現(xiàn)錯(cuò)誤,include() 函數(shù)會(huì)生成警告,但腳本會(huì)繼續(xù)執(zhí)行。require() 函數(shù)會(huì)產(chǎn)生致命錯(cuò)誤,腳本會(huì)停止。

我的建議是 99.9% 的時(shí)間里只使用 require_once。

使用 requireinclude 代替意味著您的代碼在其他地方不可重用,即您引入的腳本實(shí)際上是在執(zhí)行代碼,而不是提供類或某些類功能庫。

? Source: stackoverflow.com

Q6: PHP 中的 stdClass 是什么?#

主題: PHP
難度: ⭐⭐

stdClass 只是將其他類型強(qiáng)制轉(zhuǎn)換為對(duì)象時(shí)使用的通用” 空’’類。stdClass 不是 PHP 中對(duì)象的基類。這可以很容易地證明:

class Foo{} $foo = new Foo(); echo ($foo instanceof stdClass)?'Y':'N'; // 輸出'N'

對(duì)于匿名對(duì)象,動(dòng)態(tài)屬性等很有用。

考慮 StdClass 的一種簡(jiǎn)單使用場(chǎng)景是替代關(guān)聯(lián)數(shù)組。請(qǐng)參見下面的示例,該示例顯示 json_decode() 如何允許獲取 StdClass 實(shí)例或關(guān)聯(lián)數(shù)組。
同樣但未在本示例中顯示的 SoapClient::__soapCall 返回一個(gè) StdClass 實(shí)例。

//帶有StdClass的示例 $json = '{ "foo": "bar", "number": 42 }'; $stdInstance = json_decode($json);  echo $stdInstance - > foo.PHP_EOL; //"bar" echo $stdInstance - > number.PHP_EOL; //42  //Example with associative array $array = json_decode($json, true);  echo $array['foo'].PHP_EOL; //"bar" echo $array['number'].PHP_EOL; //42

? 源自: stackoverflow.com

Q7: PHP 中的 die () 和 exit () 函數(shù)有什么不同?#

話題: PHP
困難: ⭐⭐

沒有區(qū)別,它們是一樣的。 選擇 die() 而不是 exit() 的唯一好處可能是你節(jié)省了額外鍵入一個(gè)字母的時(shí)間.

? 源自: stackoverflow.com

Q8: 它們之間的主要區(qū)別是什么#

話題: PHP
困難: ⭐⭐

constdefine 的根本區(qū)別在于,const 在編譯時(shí)定義常量,而 define 在運(yùn)行時(shí)定義常量。

const FOO = 'BAR'; define('FOO', 'BAR');  // but if (...) {     const FOO = 'BAR';    // 無效 } if (...) {     define('FOO', 'BAR'); // 有效 }

同樣在 PHP 5.3 之前,const 命令不能在全局范圍內(nèi)使用。你只能在類中使用它。當(dāng)你想要設(shè)置與該類相關(guān)的某種常量選項(xiàng)或設(shè)置時(shí),應(yīng)使用此選項(xiàng)?;蛘吣憧赡芟胍?jiǎng)?chuàng)建某種枚舉。一個(gè)好的 const 用法的例子是擺脫了魔術(shù)數(shù)字。

Define 可以用于相同的目的,但只能在全局范圍內(nèi)使用。它應(yīng)該僅用于影響整個(gè)應(yīng)用程序的全局設(shè)置。

除非你需要任何類型的條件或表達(dá)式定義,否則請(qǐng)使用 consts 而不是 define()—— 這僅僅是為了可讀性!

? 源自: stackoverflow.com

Q9: isset () 和 array_key_exists () 之間有什么區(qū)別?#

話題: PHP
困難: ⭐⭐

  • array_key_exists 它會(huì)告訴你數(shù)組中是否存在鍵,并在 $a 不存在時(shí)報(bào)錯(cuò)。
  • 如果 key 或變量存在且不是 nullisset 才會(huì)返回 true。當(dāng) $a 不存在時(shí),isset 不會(huì)報(bào)錯(cuò)。

考慮:

$a = array('key1' => 'Foo Bar', 'key2' => null);  isset($a['key1']);             // true array_key_exists('key1', $a);  // true  isset($a['key2']);             // false array_key_exists('key2', $a);  // true

? 源自: stackoverflow.com

Q10: var_dump () 和 print_r () 有什么不同?#

話題: PHP
困難: ⭐⭐

  • var_dump 函數(shù)用于顯示變量 / 表達(dá)式的結(jié)構(gòu)化信息,包括變量類型和變量。數(shù)組遞歸瀏覽,縮進(jìn)值以顯示結(jié)構(gòu)。它還顯示哪些數(shù)組值和對(duì)象屬性是引用。

  • print_r() 函數(shù)以我們可讀的方式顯示有關(guān)變量的信息。數(shù)組值將以鍵和元素的格式顯示。類似的符號(hào)用于對(duì)象。

考慮:

$obj = (object) array('qualitypoint', 'technologies', 'India');

var_dump($obj) 將在屏幕的輸出下方顯示:

object(stdClass)#1 (3) {  [0]=> string(12) "qualitypoint"  [1]=> string(12) "technologies"  [2]=> string(5) "India" }
stdClass Object (   [0] => qualitypoint  [1] => technologies  [2] => India )

? 源自: stackoverflow.com

Q11: 解釋不同的 PHP 錯(cuò)誤是什么#

話題: PHP
困難: ⭐⭐

  • notice 不是一個(gè)嚴(yán)重的錯(cuò)誤,它說明執(zhí)行過程中出現(xiàn)了一些錯(cuò)誤,一些次要的錯(cuò)誤,比如一個(gè)未定義的變量。
  • 當(dāng)出現(xiàn)更嚴(yán)重的錯(cuò)誤,如 include () 命令引入不存在的文件時(shí),會(huì)給出警告 warning。 這個(gè)錯(cuò)誤和上面的錯(cuò)誤發(fā)生,腳本都將繼續(xù)。
  • fatal error 致命錯(cuò)誤將終止代碼。未能滿足 require () 將生成這種類型的錯(cuò)誤。

? 源自: pangara.com

Q12: 如何在 PHP 中啟用錯(cuò)誤報(bào)告?

話題: PHP
困難: ⭐⭐

檢查 php.ini 中的 “display_errors” 是否等于 “on”,或者在腳本中聲明 “ini_set('display_error',1)”。

然后,在你的代碼中包含 “ERROR_REPORTING(E_ALL)”,以便在腳本執(zhí)行期間顯示所有類型的錯(cuò)誤消息。
? 源自: codementor.io

Q13: 使用默認(rèn)參數(shù)聲明某些函數(shù)

話題: PHP
困難: ⭐⭐

思考:

function showMessage($hello = false){   echo ($hello) ? 'hello' : 'bye'; }

? 源自: codementor.io

Q14: PHP 是否支持多重繼承?

話題: PHP
困難: ⭐⭐

PHP 只支持單一繼承;這意味著使用關(guān)鍵字’extended’只能從一個(gè)類擴(kuò)展一個(gè)類。

? 源自: guru99.com

Q15: 在 PHP 中,對(duì)象是按值傳遞還是按引用傳遞?

話題: PHP
困難: ⭐⭐

在 PHP 中,通過傳遞的對(duì)象。

? 源自: guru99.com

Q16:$a != $b 和 $a !== $b ,之間有什么區(qū)別?

話題: PHP
困難: ⭐⭐

!= 表示 不等于 (如果 $a 不等于 $b,則為 True), !== 表示 不全等 (如果 $a 與 $b 不相同,則為 True).

? 源自: guru99.com

Q17: 在 PHP 中,什么是 PDO?

話題: PHP
困難: ⭐⭐

PDO 代表 PHP 數(shù)據(jù)對(duì)象。

它是一組 PHP 擴(kuò)展,提供核心 PDO 類和數(shù)據(jù)庫、特定驅(qū)動(dòng)程序。它提供了供應(yīng)商中立、輕量級(jí)的數(shù)據(jù)訪問抽象層。因此,無論我們使用哪種數(shù)據(jù)庫,發(fā)出查詢和獲取數(shù)據(jù)的功能都是相同的。它側(cè)重于數(shù)據(jù)訪問抽象,而不是數(shù)據(jù)庫抽象。

? 源自: github.com/Bootsity

Q18: 說明我們?nèi)绾卧?PHP 中處理異常?

Topic: PHP
Difficulty: ⭐⭐

當(dāng)程序執(zhí)行出現(xiàn)異常報(bào)錯(cuò)時(shí),后面的代碼將不會(huì)再執(zhí)行,這時(shí) PHP 將會(huì)嘗試匹配第一個(gè) catch 塊進(jìn)行異常的處理,如果沒有捕捉到異常程序?qū)?huì)報(bào)致命錯(cuò)誤并顯示”Uncaught Exception”。
可以在 PHP 中拋出和捕獲異常。

為了處理異常,代碼可以被包圍在”try” 塊中.
每個(gè) try 必須至少有一個(gè)對(duì)應(yīng)的 catch 塊 。多個(gè)不同的 catch 塊可用于捕獲不同類的異常。
在 catch 塊中也可以拋出異常(或重新拋出之前的異常)。

思考:

try {     print "this is our try block n";     throw new Exception(); } catch (Exception $e) {     print "something went wrong, caught yah! n"; } finally {     print "this part is always executed n"; }

? Source: github.com/Bootsity

Q19: 區(qū)分 echo 和 print ()

Topic: PHP
Difficulty: ⭐⭐

echoprint 基本上是一樣的。他們都是用來打印輸出數(shù)據(jù)的。

區(qū)別在于:

  • echo 沒有返回值,而 print 的返回值為 1,因此 print 可以在表達(dá)式中使用。
  • echo 可以接受多個(gè)參數(shù)一起輸出 (但是這種多個(gè)的輸出方式很少見),而 print 一次只可以輸出一個(gè)參數(shù)。
  • echo 的輸出比 print 效率要高一些 .

? Source: github.com/Bootsity

Q20: require_once 和 require 在什么場(chǎng)景下使用?

Topic: PHP
Difficulty: ⭐⭐⭐

require_once() 作用與 require() 的作用是一樣的,都是引用或包含外部的一個(gè) php 文件,require_once() 引入文件時(shí)會(huì)檢查文件是否已包含,如果已包含,不再包含 (require) 它。

我建議在 99.9% 的時(shí)候要使用 require_once

使用 requireinclude 意味著您的代碼不可在其他地方重用,即您要拉入的腳本實(shí)際上是在執(zhí)行代碼,而不是提供類或某些函數(shù)庫。

? Source: stackoverflow.com

Q21: 判斷 PHP 數(shù)組是否是關(guān)聯(lián)數(shù)組

Topic: PHP
Difficulty: ⭐⭐⭐

思考:

function has_string_keys(array $array) {   return count(array_filter(array_keys($array), 'is_string')) > 0; }

如果 $array 至少有一個(gè)字符串類型的 key ,它將被視為關(guān)聯(lián)數(shù)組。

? Source: stackoverflow.com

Q22: 如何將變量和數(shù)據(jù)從 PHP 傳至 Javascript

Topic: PHP
Difficulty: ⭐⭐⭐

這里有幾種實(shí)現(xiàn)方法:

  • 使用 Ajax 從服務(wù)端獲取你需要的數(shù)據(jù)。

思考 get-data.php:

echo json_encode(42);

思考 index.html:

<script>     function reqListener () {       console.log(this.responseText);     }      var oReq = new XMLHttpRequest(); // new 一個(gè)請(qǐng)求對(duì)象     oReq.onload = function() {         // 在這里你可以操作響應(yīng)數(shù)據(jù)         // 真實(shí)的數(shù)據(jù)來自 this.responseText         alert(this.responseText); // 將提示: 42     };     oReq.open("get", "get-data.php", true);     //                               ^ 不要阻塞的其余部分執(zhí)行。     //                                 不要等到請(qǐng)求結(jié)束再繼續(xù)。     oReq.send(); </script>
  • 可以在網(wǎng)頁任何地方輸出數(shù)據(jù),然后使用 JavaScript 從 DOM 中獲取信息.
<div id="dom-target" style="display: none;">     <?php         $output = "42"; // 此外, 做一些操作,獲得 output.         echo htmlspecialchars($output); /* 你必須避免特殊字符,不然結(jié)果將是無效HTML。 */     ?> </div> <script>     var div = document.getElementById("dom-target");     var myData = div.textContent; </script>
  • 直接在 JavaScript 代碼中 echo 數(shù)據(jù)。
<script>     var data = <?php echo json_encode("42", JSON_HEX_TAG); ?>; // Don't forget the extra semicolon! </script>

? Source: stackoverflow.com

Q23: 有一個(gè)方法可以復(fù)制一個(gè) PHP 數(shù)組至另一個(gè)數(shù)組嗎?

Topic: PHP
Difficulty: ⭐⭐⭐

PHP 數(shù)組通過復(fù)制進(jìn)行賦值,而對(duì)象通過引用進(jìn)行賦值。所有默認(rèn)情況下,PHP 將復(fù)制這個(gè)數(shù)組。這里有一個(gè) PHP 參考,一目了然:

$a = array(1,2); $b = $a; // $b 是一個(gè)不同的數(shù)組 $c = &$a; // $c 是 $a 的引用

? Source: stackoverflow.com

Q24: What will be returned by this code?

Topic: PHP
Difficulty: ⭐⭐⭐

Consider the code:

$a = new stdClass(); $a->foo = "bar"; $b = clone $a; var_dump($a === $b);

What will be echoed to the console?


Two instances of the same class with equivalent members do NOT match the === operator. So the answer is:

bool(false)

? Source: stackoverflow.com

Q25: What will be returned by this code? Explain the result.

Topic: PHP
Difficulty: ⭐⭐⭐

Consider the code. What will be returned as a result?

$something = 0; echo ('password123' == $something) ? 'true' : 'false';

The answer is true. You should never use == for string comparison. Even if you are comparing strings to strings, PHP will implicitly cast them to floats and do a numerical comparison if they appear numerical. === is OK.

For example

'1e3' == '1000' // true

also returns true.

? Source: stackoverflow.com

Q26: What exactly is the the difference between array_map, array_walk and array_filter?

Topic: PHP
Difficulty: ⭐⭐⭐

  • array_walk takes an array and a function F and modifies it by replacing every element x with F(x).
  • array_map does the exact same thing except that instead of modifying in-place it will return a new array with the transformed elements.
  • array_filter with function F, instead of transforming the elements, will remove any elements for which F(x) is not true

? Source: stackoverflow.com

Q27: Explain the difference between exec() vs system() vs passthru()?

Topic: PHP
Difficulty: ⭐⭐⭐

  • exec() is for calling a system command, and perhaps dealing with the output yourself.
  • system() is for executing a system command and immediately displaying the output – presumably text.
  • passthru() is for executing a system command which you wish the raw return from – presumably something binary.

? Source: stackoverflow.com

Q28: How would you create a Singleton class using PHP?

Topic: PHP
Difficulty: ⭐⭐⭐

/**  * Singleton class  *  */ final class UserFactory {     /**      * Call this method to get singleton      *      * @return UserFactory      */     public static     function Instance() {         static $inst = null;         if ($inst === null) {             $inst = new UserFactory();         }         return $inst;     }      /**      * Private ctor so nobody else can instantiate it      *      */     private     function __construct() {      } }

To use:

$fact = UserFactory::Instance(); $fact2 = UserFactory::Instance();

But:

$fact = new UserFactory()

Throws an error.

? Source: stackoverflow.com

Q29: What is the difference between PDO’s query() vs execute()?

Topic: PHP
Difficulty: ⭐⭐⭐

  • query runs a standard SQL statement and requires you to properly escape all data to avoid SQL Injections and other issues.
  • execute runs a prepared statement which allows you to bind parameters to avoid the need to escape or quote the parameters. execute will also perform better if you are repeating a query multiple times.

Best practice is to stick with prepared statements and execute for increased security. Aside from the escaping on the client-side that it provides, a prepared statement is compiled on the server-side once, and then can be passed different parameters at each execution.

? Source: stackoverflow.com

Q30: What is use of Null Coalesce Operator?

Topic: PHP
Difficulty: ⭐⭐⭐

Null coalescing operator returns its first operand if it exists and is not NULL. Otherwise it returns its second operand.

Example:

$name = $firstName ?? $username ?? $placeholder ?? "Guest";

? Source: github.com/Bootsity

Q31: Differentiate between exception and error

Topic: PHP
Difficulty: ⭐⭐⭐

  • Recovering from Error is not possible. The only solution to errors is to terminate the execution. Where as you can recover from Exception by using either try-catch blocks or throwing exception back to caller.
  • You will not be able to handle the Errors using try-catch blocks. Even if you handle them using try-catch blocks, your application will not recover if they happen. On the other hand, Exceptions can be handled using try-catch blocks and can make program flow normal if they happen.
  • Exceptions are related to application where as Errors are related to environment in which application is running.

? Source: github.com/Bootsity

Q32: What are the exception class functions?

Topic: PHP
Difficulty: ⭐⭐⭐

There are following functions which can be used from Exception class.

  • getMessage() ? message of exception
  • getCode() ? code of exception
  • getFile() ? source filename
  • getLine() ? source line
  • getTrace() ? n array of the backtrace()
  • getTraceAsString() ? formated string of trace
  • Exception::__toString gives the string representation of the exception.

? Source: github.com/Bootsity

Q33: Differentiate between parameterised and non parameterised functions

Topic: PHP
Difficulty: ⭐⭐⭐

  • Non parameterised functions don’t take any parameter at the time of calling.
  • Parameterised functions take one or more arguments while calling. These are used at run time of the program when output depends on dynamic values given at run time There are two ways to access the parameterised function:
    • call by value: (here we pass the value directly )

    • call by reference: (here we pass the address location where the value is stored)

? Source: github.com/Bootsity

Q34: Explain function call by reference

Topic: PHP
Difficulty: ⭐⭐⭐

In case of call by reference, actual value is modified if it is modified inside the function. In such case, we need to use & symbol with formal arguments. The & represents reference of the variable.

Example:

function adder(&$str2) {       $str2 .= 'Call By Reference';   } $str = 'This is ';   adder($str);   echo $str;

Output:

This is Call By Reference

? Source: github.com/Bootsity

Q35: Why do we use extract()?

Topic: PHP
Difficulty: ⭐⭐⭐

The extract() function imports variables into the local symbol table from an array.
This function uses array keys as variable names and values as variable values. For each element it will create a variable in the current symbol table.
This function returns the number of variables extracted on success.

Example:

$a = "Original"; $my_array = array("a" => "Cat","b" => "Dog", "c" => "Horse"); extract($my_array); echo "$a = $a; $b = $b; $c = $c";

Output:

$a = Cat; $b = Dog; $c = Horse

? Source: github.com/Bootsity

Q36: explain what is a closure in PHP and why does it use the “use” identifier?

Topic: PHP
Difficulty: ⭐⭐⭐⭐

Consider this code:

public function getTotal($tax) {     $total = 0.00;      $callback =         function ($quantity, $product) use ($tax, &$total)         {             $pricePerItem = constant(__CLASS__ . "::PRICE_" .                 strtoupper($product));             $total += ($pricePerItem * $quantity) * ($tax + 1.0);         };      array_walk($this->products, $callback);     return round($total, 2); }

Could you explain why use it?


This is how PHP expresses a closure. Basically what this means is that you are allowing the anonymous function to “capture” local variables (in this case, $tax and a reference to $total) outside of it scope and preserve their values (or in the case of $total the reference to $total itself) as state within the anonymous function itself.

A closure is a separate namespace, normally, you can not access variables defined outside of this namespace.

  • use allows you to access (use) the succeeding variables inside the closure.
  • use is early binding. That means the variable values are COPIED upon DEFINING the closure. So modifying $tax inside the closure has no external effect, unless it is a pointer, like an object is.
  • You can pass in variables as pointers like in case of &$total. This way, modifying the value of $total DOES HAVE an external effect, the original variable’s value changes.

? Source: stackoverflow.com

Q37: What exactly are late static bindings in PHP?

Topic: PHP
Difficulty: ⭐⭐⭐⭐

Basically, it boils down to the fact that the self keyword does not follow the same rules of inheritance. self always resolves to the class in which it is used. This means that if you make a method in a parent class and call it from a child class, self will not reference the child as you might expect.

Late static binding introduces a new use for the static keyword, which addresses this particular shortcoming. When you use static, it represents the class where you first use it, ie. it ‘binds’ to the runtime class.

Consider:

class Car {     public static     function run() {         return static::getName();     }      private static     function getName() {         return 'Car';     } }  class Toyota extends Car {     public static     function getName() {         return 'Toyota';     } }  echo Car::run(); // Output: Car echo Toyota::run(); // Output: Toyota

? Source: stackoverflow.com

Q38: How to measure execution times of PHP scripts?

Topic: PHP
Difficulty: ⭐⭐⭐⭐

I want to know how many milliseconds a PHP while-loop takes to execute. Could you help me?


You can use the microtime function for this.

Consider:

$start = microtime(true); while (...) {  } $time_elapsed_secs = microtime(true) - $start;

? Source: stackoverflow.com

Q39: What is the best method to merge two PHP objects?

Topic: PHP
Difficulty: ⭐⭐⭐⭐

//We have this: $objectA->a; $objectA->b; $objectB->c; $objectB->d;  //We want the easiest way to get: $objectC->a; $objectC->b; $objectC->c; $objectC->d;

This works:

$obj_merged = (object) array_merge((array) $obj1, (array) $obj2);

You may also use array_merge_recursive to have a deep copy behavior.

One more way to do that is:

foreach($objectA as $k => $v) $objectB->$k = $v;

This is faster than the first answer in PHP versions < 7 (estimated 50% faster). But in PHP >= 7 the first answer is something like 400% faster.

? Source: stackoverflow.com

Q40: Compare mysqli or PDO – what are the pros and cons?

Topic: PHP
Difficulty: ⭐⭐⭐⭐

Let’s name some:

  • PDO is the standard, it’s what most developers will expect to use.

  • Moving an application from one database to another isn’t very common, but sooner or later you may find yourself working on another project using a different RDBMS. If you’re at home with PDO then there will at least be one thing less to learn at that point.

  • A really nice thing with PDO is you can fetch the data, injecting it automatically in an object.

  • PDO has some features that help agains SQL injection

  • In sense of speed of execution MySQLi wins, but unless you have a good wrapper using MySQLi, its functions dealing with prepared statements are awful. inserts – almost equal, selects – mysqli is2.5% faster for non-prepared statements/6.7% faster for prepared statements.

? Source: stackoverflow.com

Q41: What is use of Spaceship Operator?

Topic: PHP
Difficulty: ⭐⭐⭐⭐

This <=> operator will offer combined comparison in that it will:

  • Return 0 if values on either side are equal
  • Return 1 if value on the left is greater
  • Return -1 if the value on the right is greater

Consider:

//Comparing Integers echo 1 <= > 1; //outputs 0 echo 3 <= > 4; //outputs -1 echo 4 <= > 3; //outputs 1  //String Comparison  echo "x" <= > "x"; // 0 echo "x" <= > "y"; //-1 echo "y" <= > "x"; //1

? Source: github.com/Bootsity

Q42: Does PHP have threading?

Topic: PHP
Difficulty: ⭐⭐⭐⭐

Standard php does not provide any multithreading but there is an (experimental) extension that actually does – pthreads. The next best thing would be to simply have one script execute another via CLI, but that’s a bit rudimentary. Depending on what you are trying to do and how complex it is, this may or may not be an option.

? Source: github.com/Bootsity

Q43: Is PHP single or multi threaded?

Topic: PHP
Difficulty: ⭐⭐⭐⭐

PHP is not single threaded by nature. It is, however, the case that the most common installation of PHP on unix systems is a single threaded setup, as is the most common Apache installation, and nginx doesn’t have a thread based architecture whatever. In the most common Windows setup and some more advanced unix setups, PHP can and does operate multiple interpreter threads in one process.

PHP as an interpreter had support for multi-threading since the year 2000.

? Source: github.com/Bootsity

Q44: Provide some ways to mimic multiple constructors in PHP

Topic: PHP
Difficulty: ⭐⭐⭐⭐⭐

It’s known you can’t put two __construct functions with unique argument signatures in a PHP class but I’d like to do something like this:

class Student  {    protected $id;    protected $name;    // etc.     public function __construct($id){        $this->id = $id;       // other members are still uninitialised    }     public function __construct($row_from_database){        $this->id = $row_from_database->id;        $this->name = $row_from_database->name;        // etc.    } }

What is the best way to achieve this in PHP?


I’d probably do something like this:

class Student {     public function __construct() {         // allocate your stuff     }      public static function withID( $id ) {         $instance = new self();         $instance->loadByID( $id );         return $instance;     }      public static function withRow( array $row ) {         $instance = new self();         $instance->fill( $row );         return $instance;     }      protected function loadByID( $id ) {         // do query         $row = my_awesome_db_access_stuff( $id );         $this->fill( $row );     }      protected function fill( array $row ) {         // fill all properties from array     } }

Then if i want a Student where i know the ID:

$student = Student::withID( $id );

Technically you’re not building multiple constructors, just static helper methods, but you get to avoid a lot of spaghetti code in the constructor this way.

Another way is to use the mix of factory and fluent style:

class Student {     protected $firstName;     protected $lastName;     // etc.      /**      * Constructor      */     public function __construct() {         // allocate your stuff     }      /**      * Static constructor / factory      */     public static function create() {         $instance = new self();         return $instance;     }      /**      * FirstName setter - fluent style      */     public function setFirstName( $firstName) {         $this->firstName = $firstName;         return $this;     }      /**      * LastName setter - fluent style      */     public function setLastName( $lastName) {         $this->lastName = $lastName;         return $this;     } }  // create instance $student= Student::create()->setFirstName("John")->setLastName("Doe");

? Source: stackoverflow.com

Q45: How could we implement method overloading in PHP?

Topic: PHP
Difficulty: ⭐⭐⭐⭐⭐

You cannot overload PHP functions. Function signatures are based only on their names and do not include argument lists, so you cannot have two functions with the same name.

You can, however, declare a variadic function that takes in a variable number of arguments. You would use func_num_args() and func_get_arg() to get the arguments passed, and use them normally.

Consider:

function myFunc() {     for ($i = 0; $i < func_num_args(); $i++) {         printf("Argument %d: %sn", $i, func_get_arg($i));     } }  /* Argument 0: a Argument 1: 2 Argument 2: 3.5 */ myFunc('a', 2, 3.5);

? Source: github.com/Bootsity

為了處理異常,代碼可能被包圍在一個(gè) try 塊中。

每個(gè) try 必須至少有一個(gè)提示。

原文地址:https://dev.to/fullstackcafe/45-important-php-interview-questions-that-may-land-you-a-job-1794

推薦學(xué)習(xí):《PHP視頻教程》

贊(0)
分享到: 更多 (0)
網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)
gmnon.cn-疯狂蹂躏欧美一区二区精品,欧美精品久久久久a,高清在线视频日韩欧美,日韩免费av一区二区
黄色a级片免费| 欧美日韩国产精品激情在线播放| 无码熟妇人妻av在线电影| 色婷婷成人在线| 国产成人av影视| av免费中文字幕| 无码专区aaaaaa免费视频| 91免费国产精品| 400部精品国偷自产在线观看| gogogo高清免费观看在线视频| 日韩视频免费在线播放| 丰满人妻中伦妇伦精品app| 日日橹狠狠爱欧美超碰| 国产精品无码一区二区在线| 97视频久久久| 激情婷婷综合网| 免费看污污网站| 一二三av在线| 成人免费毛片在线观看| 红桃一区二区三区| 69sex久久精品国产麻豆| 成熟丰满熟妇高潮xxxxx视频| 黄页网站大全在线观看| 免费看a级黄色片| 99国产精品久久久久久| 日韩精品 欧美| 日本精品www| 乌克兰美女av| 先锋影音男人资源| 国产精品无码av在线播放| 久久久999视频| 永久av免费在线观看| 91成人综合网| 不卡av免费在线| www.18av.com| 鲁一鲁一鲁一鲁一av| 男人天堂a在线| 一区二区免费av| 97超碰人人澡| 在线视频观看91| 国产特级黄色大片| 天天爱天天做天天操| 逼特逼视频在线| 国产91porn| www.久久av.com| 免费黄色特级片| 日韩美女爱爱视频| 天堂v在线视频| av片中文字幕| 黄页网站大全在线观看| gogogo免费高清日本写真| 日日碰狠狠躁久久躁婷婷| 四虎4hu永久免费入口| 色天使在线观看| 午夜精品久久久内射近拍高清| 日韩精品第1页| 手机免费av片| 色呦色呦色精品| 尤蜜粉嫩av国产一区二区三区| 欧美成人高潮一二区在线看| 永久免费网站视频在线观看| 色啦啦av综合| www.污网站| 小早川怜子一区二区三区| 国产性生交xxxxx免费| 国内外成人激情视频| 国产91沈先生在线播放| www.成年人视频| 中文字幕乱码免费| 黑人巨茎大战欧美白妇| 真人做人试看60分钟免费| ijzzijzzij亚洲大全| 成人手机视频在线| 超碰在线免费观看97| 国产精品无码乱伦| 国产盗摄视频在线观看| 成人在线免费高清视频| 97在线国产视频| 丰满人妻中伦妇伦精品app| 成人性做爰aaa片免费看不忠| 国产成人综合一区| wwwwwxxxx日本| 亚洲天堂av免费在线观看| 黄色a级在线观看| a级黄色小视频| 国产成人在线免费看| 五月婷婷激情久久| 欧洲美女和动交zoz0z| 国产在线视频综合| 久久久久久久久久久视频| 性生活免费在线观看| jizz18女人| 亚洲精品久久久久久久蜜桃臀| 国产午夜伦鲁鲁| 视频区 图片区 小说区| 欧美中文字幕在线观看视频| 欧美国产亚洲一区| www.51色.com| 精品国产一区三区| 在线免费av播放| 无码 制服 丝袜 国产 另类| 男人亚洲天堂网| 一级全黄肉体裸体全过程| 亚洲色成人一区二区三区小说| 亚洲一级片av| 欧美日韩激情视频在线观看| 欧美爱爱视频网站| 欧美日韩亚洲一二三| 国产精品igao激情视频 | 成年人网站大全| 精品亚洲视频在线| 国产精品网站免费| 99久久久无码国产精品性色戒| 91好吊色国产欧美日韩在线| 亚洲精品20p| 日韩av一二三四区| 国产精品免费看久久久无码| 色综合手机在线| 日本国产在线播放| 丁香六月激情网| 手机av在线网站| 国产又黄又猛又粗| 少妇性饥渴无码a区免费| 强开小嫩苞一区二区三区网站| jizzzz日本| 午夜宅男在线视频| 国产精彩免费视频| 欧美精品99久久| 国产在线播放观看| www.xxx麻豆| 日韩精品久久一区二区| 欧美 国产 精品| 国产成人精品免费看在线播放| 无尽裸体动漫2d在线观看| 黄色国产小视频| 成人午夜视频免费在线观看| 国产91对白刺激露脸在线观看| 国产不卡一区二区视频| 9久久9毛片又大又硬又粗| 97超碰在线人人| 国产3p露脸普通话对白| 日韩av在线播放不卡| 女人帮男人橹视频播放| av免费观看大全| 日本精品一区在线观看| 免费在线观看日韩视频| 青青草av网站| the porn av| 中文字幕一区久久| www成人免费| 18禁免费无码无遮挡不卡网站| 人妻有码中文字幕| 不卡av免费在线| 日本一级淫片演员| 美女黄色免费看| 日韩av资源在线| 欧美激情第3页| 性做爰过程免费播放| 久久久久免费看黄a片app| 老熟妇仑乱视频一区二区 | 无需播放器的av| 午夜激情视频网| 丰满爆乳一区二区三区| 在线免费视频a| 91香蕉视频网址| 俄罗斯av网站| 天天操天天干天天做| 久久99久久99精品| 亚洲综合婷婷久久| 日本国产中文字幕| 毛片av免费在线观看| 免费久久久久久| 一本久道中文无码字幕av| 一级性生活视频| 国产免费999| 久无码久无码av无码| 福利视频999| 亚洲一区二区三区四区五区xx| 99九九精品视频| 日韩中文字幕免费在线| 日韩精品久久一区二区| 一道本在线免费视频| 春日野结衣av| 免费的av在线| 中文字幕丰满乱码| 日本xxxxxxx免费视频| 日本福利视频一区| 神马午夜伦理影院| 国产无遮挡猛进猛出免费软件| 少妇高清精品毛片在线视频 | 亚洲第一狼人区| 国产视频一区二区三区在线播放 | 超碰在线免费av| jizz大全欧美jizzcom| 日韩欧美精品在线观看视频| 91亚洲精品国产| 国产在线视频在线| 丁香色欲久久久久久综合网| 成人在线观看www| 国产手机视频在线观看|