




已阅读5页,还剩6页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
PHP5.3新功能与不兼容特性整理1.支持命名空间 PHP5.3之后的版本引入了名称空间的支持,此举的好处是不同模块之间分隔方式变得天然纯正,以往PHP要实现不同模块之间的划分通常会各为其政,有 类PEAR或ZendFramework的, 有像Drupal以模块区分等等,在已有项目内引入了第三方库经常会担心是否有全局名称的冲突,PHP5.3后这种担心可大大减低, 其为我们提供了一种主流解决方案。 关于此特性也颇具争议有人认为PHP的特点就是简单,在PHP5之后越加复杂违背了最初的理念,不过鄙人拙见认为语言就是应对解决问题而生有更好的解决方式就应该提倡。echoValue; $test = new namespaceDemodemoClass();$test-echoValue();/* * output: * i am namespaceDemodemoClass-echoValue */?2.支持GOTO语句 GOTO语句曾经颇受争议, 后来经过大师们很多次较量后才最终确认合理使用有益无害,PHP5.3之后也引入了此语句。?phpfor( $i = 1; $i 3.新的静态魔术方法_callStatic. 5.2支持通过魔术方法处理不存在方法的调用, 但其只支持非静态方法, 5.3版本引入了静态魔术方法。?php/* * _callStatic魔术方法使用方式 */class callStatic public static function _callStatic( $name, $arguments ) echo function name:; echo $name . ; echo function arguments:; print_r( $arguments ); $callStatic = new callStatic();echo $callStatic:notExistsFun( array( param1 , param2 ) );/* * output: * function name:notExistsFun * function arguments:Array ( 0 = Array ( 0 = param1 1 = param2 ) ) */?4.新的匿名魔术方法 _invoke. 如果对象实现了_invoke魔术方法就可将其作为函数直接调用,实例化对象之后可用匿名函数的形式直接调用。?phpclass invokeDemo public function _invoke( $param1 , $param2 ) print_r( array( $param1 , $param2 ) ); echo this is invoke magic function; $invokeDemo = new invokeDemo();$invokeDemo( param1String , array( 1 , 2 , 3) );/* * output: * Array ( 0 = param1String 1 = Array ( 0 = 1 1 = 2 2 = 3 ) ) * this is invoke magic function */?5.动态调用静态属性。PHP5.2之前静态方法是不支持用变量指定方法名称并动态调用的, 5.3之后引入了此功能。6.支持匿名函数(lumbda). 5.3之后引入了匿名函数,对Javascript了解的人对其并不陌生它占了JS的重头戏,灵活运用匿名函数会带来很多便利,PHP的匿名函数作用域 和函数的作用域相同,不过可以通过内置语法USE传入全局变量,当然也可以在函数内部使用global或$GLOBALS调用全局变量。?php$arr = array( 3, 2, 5, 6, 1 );usort( $arr, function( $a, $b ) if( $a = $b ) return 0; return ($a 1 1 = 2 2 = 3 3 = 5 4 = 6 ) */7.新的三元操作符 新三元操作符?:在判断表达式结果为TRUE时会返回此判断表达式的结果即?:之前的值, False时返回?:之后的值。8.全局空间内const代替define()函数可直接使用9.json_encode支持强制转换对象JSON 5.3后的json_enocde可通过参数强制转换数组为对象形式JSON。?php$arr = array( 1 , 2 , 3 );echo json_encode( $arr ) . ;echo json_encode( $arr , JSON_FORCE_OBJECT );/* * output: * 1,2,3 * 0:1,1:2,2:3 */?10.默认启用SPL支持。 SPL提供了很多激动人心的特性,具体包括数据结构类、迭代类、接口、异常、文件等通用功能类。 数据结构提供了双向链表、栈、队列、堆、优先队列、固定大小数组、对象存储器, 但效率是否高于数组实现需要在应用内具体测试,方才测试队列类的效能发现低于原生实现, 不过固定数组的效率还是很可观的,下面代码是对固定大小数组的一个测试, 速度快了近1倍,详细代码如下:$i=1000000;$spl = new SplFixedArray( 1000000 );while ($i-) $spl$i = SM;SplFixedArray数组运行时间与内存使用大小:Running time:0.2420928478241Memory usage:52324152Array数组运行时间与内存使用大小:Running time:0.42152786254883Memory usage:10051799211.延迟静态绑定。12.循环垃圾收集,能够发现对象的循环引用并自动回收内存13.支持phar归档不兼容的特性:1.atsort,natcasesort,usort,uasort,array_flip等数组函数不支持传入对象。2.魔术方法必须声明为公共属性3.从PECL移除的库,ncurses, fpdf, dbase, fbsql, ming.4.废弃的tick, ereg正则。5.namespace,Closure变成了保留值6.http Stream流支持200-399全部状态7.去除了magic quotes和register globals特性8.出错提示信息与5.2版本相比有变化9.以下配置项在PHP5.3将产生警告define_syslog_variablesregister_globalsregister_long_arrayssafe_modemagic_quotes_gpcmagic_quotes_runtime magic_quotes_sybase新的函数:PHP Core: array_replace() Replaces elements from passed arrays into one array. array_replace_recursive() Recursively replaces elements from passed arrays into one array. class_alias() Creates an alias for a user defined class. forward_static_call() Call a user function from a method context. forward_static_call_array() Call a user function from a method context, with the arguments contained in an array. gc_collect_cycles() Forces collection of any existing garbage cycles. gc_disable() Deactivates the circular reference collector. gc_enable() Activates the circular reference collector. gc_enabled() Returns the status of the circular reference collector. get_called_class() Return the name of the class a static method is called in. gethostname() Return the current host name for the local machine. header_remove() Removes an HTTP header previously set using the header() function. lcfirst() Make a strings first character lowercase. parse_ini_string() Parse a configuration string. quoted_printable_encode() Convert an 8 bit string to a quoted-printable string. str_getcsv() Parse a CSV string into an array. stream_context_set_default() Set the default stream context. stream_supports_lock() Return TRUE if the stream supports locking. stream_context_get_params() Retrieve parameters from a stream context. streamWrapper:stream_cast() Retrieve the underlying stream resource. streamWrapper:stream_set_option() Change stream optionsDate/Time: date_add() Adds an amount of days, months, years, hours, minutes and seconds to a DateTime object. date_create_from_format() Returns a new DateTime object formatted according to the given format. date_diff() Returns the difference between two DateTime objects. date_get_last_errors() Returns the warnings and errors from the last date/time operation. date_parse_from_format() Get infoformation about a given date. date_sub() Subtracts an amount of days, months, years, hours, minutes and seconds from a DateTime object. timezone_version_get() Returns the version of the timezonedb.GMP: gmp_testbit() Tests whether a bit is set.Hash: hash_copy() Copy hashing context.IMAP: imap_gc() Clears IMAP cache. imap_utf8_to_mutf7() Encode a UTF-8 string to modified UTF-7. imap_mutf7_to_utf8() Decode a modified UTF-7 string to UTF-8.JSON: json_last_error() Returns the last JSON error that occurred.MySQL Improved: mysqli_fetch_all() Fetches all result rows as an associative array, a numeric array, or both. mysqli_get_connection_stats() Returns statistics about the client connection. mysqli_poll() Poll connections. mysqli_reap_async_query() Get result from async query.OpenSSL: openssl_random_pseudo_bytes() Returns a string of the given length specified, filled with pseudo-random bytes.PCNTL: pcntl_signal_dispatch() Calls signal handlers for pending signals. pcntl_sigprocmask() Sets and retrieves blocked signals. pcntl_sigtimedwait() Wait for signals with a timeout. pcntl_sigwaitinfo() Wait for signals.PCRE: preg_filter() Perform a regular expression search and replace, reutrning only results which matched the pattern.Semaphore: msg_queue_exists() Check whether a message queue exists. shm_has_var() Checks whether a specific key exists inside a shared memory segment.The following functions are now natively implemented, making them available on all operating systems which can run PHP: acosh() asinh() atanh() expm1() log1p()原有函数的参数变更:PHP Core: clearstatcache() Added clear_realpath_cache and filename . copy() Added a stream context parameter, context . fgetcsv() Added escape . ini_get_all() Added details . The mail() function now supports logging of sent email. (Note: This only applies to email sent through this function.) nl2br() Added is_xhtml . parse_ini_file() Added scanner_mode . round() Added mode . stream_context_create() Added p
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 承德初一月考试卷及答案
- 达标测试人教版八年级上册物理物态变化《升华和凝华》专题测评试题(含答案解析版)
- 吴江初一中考试卷及答案
- 考点解析-人教版八年级上册物理声现象《声音的特性》综合练习试卷(解析版含答案)
- 2025年电大专科学前教育学前儿童发展心理学试题及答案
- 多源异构数据融合聚类-洞察与解读
- 2025年《汽车维修工技师》考试练习题含参考答案
- 培训效果预测分析-洞察与解读
- 2025年事业单位招聘考试审计专业能力测试试卷与答案解析
- 2025年新疆维吾尔自治区事业单位招聘考试综合类专业能力测试试卷(建筑类)真题模拟及答案
- 公司事件事故管理制度
- 2025至2030年中国渣油行业市场现状调查及发展前景研判报告
- 四川省成都市某中学2024-2025学年八年级上学期期中地理试题(原卷版)
- 广告说服的有效实现知到智慧树期末考试答案题库2025年湖南师范大学
- 医用耗材招标管理制度
- Creo软件基础操作培训
- 心理韧性培养与提升 - 课件
- 企业内部控制培训课件
- 火灾爆炸考试题及答案
- 2025年海上货物运输合同范本
- 化物所员工安全教育考试题库
评论
0/150
提交评论