Home Backend Development PHP Tutorial PHP interview questions sharing (blessed are those who are looking for a job)

PHP interview questions sharing (blessed are those who are looking for a job)

Jul 25, 2016 am 09:04 AM

  1. $tmp = 0 == "a"? 1: 2;
  2. echo $tmp;
  3. ?>
Copy code

Result 1 Int and string type cast caused ,0==="a"

0 == 0 It must be true PHP is weakly typed. . $tmp = 0 === "a"? 1: 2; echo $tmp; This is 2

4. It is known that a string is as follows: $str = "1109063 milo 1"; Use one line of code to assign 1109063 in the string to $uid, milo to $user, and 1 to $type The spaces are as follows list($uid, $user, $type) = explode(" ", $str); t is as follows list($uid, $user, $type) = explode("t", $str); list($uid, $user, $type) = sscanf($str, "%d %s %d"); $n = sscanf($auth, "%dt%s %s", $id, $first, $last);

5. List the following types of signed and unsigned ranges respectively: TINYINT SMALLINT MEDIUMINT INT TINYINT-2^7 - 2^7-10 ~ 2^8-1 SMALLINT-2^15 - 2^15-1 0 ~ 2^16-1 MEDIUMINT-2^23 - 2^23-1 0 ~ 2^24-1 INT-2^31 - 2^31-1 0 ~ 2^32-1

6. Assemble the following array into a string in one line i am milo! day day up!

  1. $arr = array(
  2. 'I', 'AM', 'MILO!', 'DAY', 'DAY', 'UP!'
  3. );
  4. ?>
  5. $str = strtolower(implode(" ",$arr));
Copy code

7. Call the following function to get the function and get the value of count

  1. function get_list($cnd = array(), &$count = false)
  2. {
  3. // Pseudo code processes $cnd and assigns datas
  4. $datas = 'i am call back' ;
  5. $count && $count = rand(1, 10000);
  6. return $datas;
  7. }
  8. ?>
  9. $count=1;
  10. $data = get_list($cnd,&$count);
  11. echo $count ;
Copy code

8. Several ways to replace the session mechanism, briefly describing their respective advantages and disadvantages mysql, memcache, and cookie maintain a unique status identification code

9. Possible reasons for the following HTTP status codes and how to deal with them 200, 301, 404, 502, 503 200 The request was successful and the response headers or data body expected by the request will be returned with this response. 301 The requested resource has been permanently moved to a new location, and any future references to this resource should use one of several URIs returned with this response. If possible, clients with link editing capabilities should automatically modify the requested address to the address returned from the server. Unless otherwise specified, this response is also cacheable. The new permanent URI should be returned in the Location field of the response. Unless this is a HEAD request, the response entity should contain a hyperlink to the new URI and a brief description. If this is not a GET or HEAD request, the browser prohibits automatic redirection unless confirmed by the user, because the conditions of the request may change accordingly.

Note: For some browsers that use the HTTP/1.0 protocol, when the POST request they send gets a 301 response, the subsequent redirect request will become a GET method.

404 The request failed. The requested resource was not found on the server. There is no information to tell the user whether the condition is temporary or permanent. If the server knows the situation, it should use the 410 status code to inform that the old resource is permanently unavailable due to some internal configuration mechanism problems, and there is no jump address. The 404 status code is widely used when the server does not want to reveal why the request was rejected or no other suitable response is available. 502 A server working as a gateway or proxy received an invalid response from an upstream server while trying to perform a request. 503 Due to temporary server maintenance or overload, the server is currently unable to process requests. This condition is temporary and will be restored after a period of time. If a delay can be expected, the response can include a Retry-After header to indicate the delay. If this Retry-After message is not given, the client SHOULD handle it the same way it handles a 500 response. Note: The existence of the 503 status code does not mean that the server must use it when it is overloaded. Some servers simply wish to deny connections from clients.

200 OK Everything is fine, and the response documents to GET and POST requests follow. 301 Moved Permanently The document requested by the client is elsewhere. The new URL is given in the Location header. The browser should automatically access the new URL. 404 Not Found The resource at the specified location cannot be found. This is also a common response. 502 Bad Gateway When the server acts as a gateway or proxy, it accesses the next server to complete the request, but the server returns an illegal response. 503 Service Unavailable The server failed to respond due to maintenance or overload. For example, a Servlet may return 503 when the database connection pool is full. The server can provide a Retry-After header when returning 503.

10. There is the following database, use the original mysql extension to connect and query the first ten rows of the user table host: 192.168.0.254 port: 3306 user: one pass:piece database: db_user table: user

  1. $link = mysql_connect("192.168.0.254:3306","one","piece") or die('Could not connect: '.mysql_error());
  2. mysql_select_db('db_user',$ link);
  3. $query = mysql_query("select * from user limit 10");
  4. while($rs = mysql_fetch_array($query,MYSQL_ASSOC))
  5. {}
Copy code

11. Use autoload($class) to realize automatic loading of classes in the Lib directory and be compatible with subdirectories

  1. $request->action = lcfirst(implode(array_map(

  2. 'ucfirst',
  3. explode('-', strtolower($request->action))
  4. ))) ;
  5. ------------------------------------------------
  6. function __autoload($class)
  7. {
  8. $cls = strtolower(str_replace("_","/",$class));

  9. if(file_exsits(LIB.$cls. '.php'))
  10. {
  11. include_once(LIB.$cls.'.php');
  12. }
  13. else
  14. {
  15. die("not found {$class} class");
  16. }
  17. }
  18. defined(" LIB",'/data/wwwroot/www.xx.com/lib/');
  19. $author = new Lib_Author();
  20. ----------------------------- ---------------------------------------
  21. function __authload($class)
  22. {
  23. $ cls = explode("_",$class);
  24. if(@is_dir($cls[1]))
  25. {
  26. if(@is_file($cls[2]))
  27. {
  28. include_once("CON_PATH".$ cls[1].'/'.$cls[2].".php");
  29. }
  30. else
  31. {
  32. dir('error');
  33. }
  34. }
  35. else if(@is_file($cls[1 ].".php"))
  36. {
  37. include_once("CON_PATH".$cls[1].".php");
  38. }
  39. else
  40. {
  41. dir('error');
  42. }
  43. }
  44. -- ----------------------------------------
  45. function __autoload($class)
  46. {
  47. $cls = explode("_",$class);
  48. $file = get_file($cls);
  49. if($file=='error')
  50. {
  51. die('error');
  52. }
  53. include_once($file);
  54. }
  55. function get_file($dir)
  56. {
  57. if(is_array($dir))
  58. {
  59. foreach($dir as $k=>$v)
  60. {
  61. $tmpdir .= $v.'/';
  62. if(is_dir('CON_PATH'.$tmpdir))
  63. {
  64. continue();
  65. }
  66. else if(is_file('CON_PATH'.$tmpdir.".php"))
  67. {
  68. return 'CON_PATH'.$ tmpdir.".php";
  69. }
  70. else
  71. {
  72. return 'error';
  73. }
  74. }
  75. return 'error';
  76. }
  77. return 'error';
  78. }

  79. defined ("CON_PATH","/data/wwwroot/www.xx.com/app/cntroller/");

  80. $sb = new controller_sb();
  81. ---------------- --------------------
  82. function __autoload_my_classes($classname)
  83. {
  84. # ... your logic to include classes here
  85. }
  86. spl_autoload_register('__autoload_my_classes');
  87. ------------------------------------------------- ----------

Copy code

12. Use set_error_handle to capture errors and output them, the level is determined by yourself

  1. set_error_handle(callback,level)

  2. function callback(int $errno , string $errstr [, string $errfile [, int $errline [, array $errcontext ]]] ){
  3. }

  4. function dealErrorHandler($errno,$errstr,$errfile,$errline)

  5. {
  6. switch($errno){
  7. case E_USER_ERROR:
  8. echo "error [$errno] $errstr fatal error on line $errline in file $errfile";
  9. break;
  10. case E_USER_WARNING:
  11. echo "my warning [$errno] $errstr":
  12. break;
  13. case E_USER_NOTICE:
  14. echo "my notice[$errno] $errstr";
  15. break;
  16. default:
  17. echo "unkonwn error type :[$errno] $errstr";
  18. break;
  19. }
  20. }
  21. set_erro_handler(dealErrorHandler);

  22. trigger_error("notice", E_USER_NOTICE);

  23. trigger_error("warning", E_USER_WARNING);
  24. trigger_error("error", E_USER_ERROR);

Copy code

13. Briefly describe two methods of shielding notice warnings of PHP programs method Initialize variables, set the error level at the beginning of the file or modify php.ini to set error_reporting set_error_handler and @suppress errors

1. Add in the program: error_reporting (E_ALL & ~E_NOTICE); 2. Or modify php.ini: error_reporting = E_ALL Change to: error_reporting = E_ALL & ~E_NOTICE 3.error_reporting(0);or modify php.inidisplay_errors=Off 1 2 3 4 Next page Last page



Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

Long URLs, often cluttered with keywords and tracking parameters, can deter visitors. A URL shortening script offers a solution, creating concise links ideal for social media and other platforms. These scripts are valuable for individual websites a

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

This is the second and final part of the series on building a React application with a Laravel back-end. In the first part of the series, we created a RESTful API using Laravel for a basic product-listing application. In this tutorial, we will be dev

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Announcement of 2025 PHP Situation Survey Announcement of 2025 PHP Situation Survey Mar 03, 2025 pm 04:20 PM

The 2025 PHP Landscape Survey investigates current PHP development trends. It explores framework usage, deployment methods, and challenges, aiming to provide insights for developers and businesses. The survey anticipates growth in modern PHP versio

Notifications in Laravel Notifications in Laravel Mar 04, 2025 am 09:22 AM

In this article, we're going to explore the notification system in the Laravel web framework. The notification system in Laravel allows you to send notifications to users over different channels. Today, we'll discuss how you can send notifications ov

See all articles