<address id="ousso"></address>
<form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
  1. php語言

    PHP面試之編程題及答案

    時間:2025-01-26 16:44:18 php語言 我要投稿
    • 相關推薦

    2017年PHP面試之編程題及答案

      在面試PHP的時候萬一遇到編程題怎么辦?以下是百分網小編精心為大家整理的PHP面試編程題及答案,希望對大家有所幫助!更多內容請關注應屆畢業生網!

    2017年PHP面試之編程題及答案

      1. 用autoload($class) 實現Lib目錄下的類的自動加載并可以兼容子目錄

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

      'ucfirst',

      explode('-', strtolower($request->action))

      )));

      ------------------------------------------------------------

      function __autoload($class)

      {

      $cls = strtolower(str_replace("_","/",$class));

      if(file_exsits(LIB.$cls.'.php'))

      {

      include_once(LIB.$cls.'.php');

      }

      else

      {

      die("not found {$class} class");

      }

      }

      defined("LIB",'/data/wwwroot/www.xx.com/lib/');

      $author = new Lib_Author();

      -----------------------------------------------------------

      function __authload($class)

      {

      $cls = explode("_",$class);

      if(@is_dir($cls[1]))

      {

      if(@is_file($cls[2]))

      {

      include_once("CON_PATH".$cls[1].'/'.$cls[2].".php");

      }

      else

      {

      dir('error');

      }

      }

      else if(@is_file($cls[1].".php"))

      {

      include_once("CON_PATH".$cls[1].".php");

      }

      else

      {

      dir('error');

      }

      }

      ---------------------------------------

      function __autoload($class)

      {

      $cls = explode("_",$class);

      $file = get_file($cls);

      if($file=='error')

      {

      die('error');

      }

      include_once($file);

      }

      function get_file($dir)

      {

      if(is_array($dir))

      {

      foreach($dir as $k=>$v)

      {

      $tmpdir .= $v.'/';

      if(is_dir('CON_PATH'.$tmpdir))

      {

      continue();

      }

      else if(is_file('CON_PATH'.$tmpdir.".php"))

      {

      return 'CON_PATH'.$tmpdir.".php";

      }

      else

      {

      return 'error';

      }

      }

      return 'error';

      }

      return 'error';

      }

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

      $sb = new controller_sb();

      ------------------------------------

      function __autoload_my_classes($classname)

      {

      # ... your logic to include classes here

      }

      spl_autoload_register('__autoload_my_classes');

      -----------------------------------------------------------

      2. 用set_error_handle 去捕獲錯誤并輸出, 級別自己定

      set_error_handle(callback,level)

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

      }

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

      {

      switch($errno){

      case E_USER_ERROR:

      echo "error [$errno] $errstr fatal error on line $errline in file $errfile";

      break;

      case E_USER_WARNING:

      echo "my warning [$errno] $errstr":

      break;

      case E_USER_NOTICE:

      echo "my notice[$errno] $errstr";

      break;

      default:

      echo "unkonwn error type :[$errno] $errstr";

      break;

      }

      }

      set_erro_handler(dealErrorHandler);

      trigger_error("notice", E_USER_NOTICE);

      trigger_error("warning", E_USER_WARNING);

      trigger_error("error", E_USER_ERROR);

      3. 簡述兩種屏蔽php程序的notice警告的方法

      初始化變量,文件開始設置錯誤級別或者修改php.ini 設置error_reporting

      set_error_handler 和 @抑制錯誤

      1.在程序中添加:error_reporting (E_ALL & ~E_NOTICE);

      2.或者修改php.ini中的:error_reporting = E_ALL

      改為:error_reporting = E_ALL & ~E_NOTICE

      3.error_reporting(0);或者修改php.inidisplay_errors=Off

      4. instanceof的作用, 經常在什么設計模式中使用

      單例模式,但是其他的模式也會用到

      5. 1023用二進制表示, 并簡述計算過程

      10-2

      1023%2=1

      511%2 =1

      255%2 =1

      127%2 =1

      63%2 =1

      31%2 =1

      15%2 =1

      7%2 =1

      3%2 =1

      1%2 =1

      0 =0

      -------------------------------------------

      1023

      2^9=

      511

      k=9

      10 9 8 7 6 5 4 3 2 1

      1 1 1 1 1 1 1 1 1 1

      ----------------------

      1023 1

      1023-1/2=511 1

      511-1/2=255 1

      255-1/2=127 1

      127-1/2=63 1

      63-1/2=31 1

      31-1/2=15 1

      15-1/2=7 1

      7-1/2=3 1

      3-1/2=1 1

      -----------------------------------------------

      2-10

      只需用將二進制數的各個位上的數從最右邊開始,最右邊的第一個數乘以二的零次方,第二個數乘以二的一次方,第三個數乘以二的二次方,依次類推可得第n個數乘以二的(n-1)次方,然后把得到的結果相加即可

      例如:110011=1*2^0+1*2^1+0*2^2+0*2^3+1*2^4+1*2^5=51

      這也可以算是一個公式就是An*2^(n-1) An表示二進制數最右邊開始的第n個數,

      將第一項第二項第三項一直到第n項用式子An*2^(n-1) 計算出來并加在一起即可

      6. 有如下數據庫, 用原生態mysql擴展去連接并查詢user表的前十行

      host: 192.168.0.254

      port: 3306

      user: one

      pass: piece

      database: db_user

      table: user

      $link = mysql_connect("192.168.0.254:3306","one","piece") or die('Could not connect: '.mysql_error());

      mysql_select_db('db_user',$link);

      $query = mysql_query("select * from user limit 10");

      while($rs = mysql_fetch_array($query,MYSQL_ASSOC))

      {}


    【PHP面試之編程題及答案】相關文章:

    2017年PHP面試編程題09-18

    php編程必學之表單驗證10-31

    PHP編程面試題集10-06

    php語言編程07-06

    PHP編程與應用06-06

    精選php面試題及答案06-01

    PHP面試題及答案06-27

    PHP Socket編程過程07-19

    PHP面試之php自帶的幾個防止sql注入的函數06-14

    <address id="ousso"></address>
    <form id="ousso"><track id="ousso"><big id="ousso"></big></track></form>
    1. 日日做夜狠狠爱欧美黑人