php5.4.0的一些小问题
晚上刚刚更新了php5.4.0,环境是Windows7 + Apache2.2 + MySQL5.1 + PHP5.4.0,php.ini没有重新更新,仍然采用之前的版本(php5.2)
如题,有两个小问题:
1,php5.4.0的命名空间空间问题:
<?phpnamespace Foo;class test{/*hello php 5.4.0*/}?>
出现:
Fatal error: Namespace declaration statement has to be the very first statement in the script in F:\htdocs\rules.php on line 2
这是啥问题啊???怎样声明都没用。。。。直接copy手册的代码也出错。。。。是php5.4自己的错误还是我配置的问题??
2,直接贴代码吧:
$phpinfo = function (){ echo 'hello world!'; } phpinfo(); $phpinfo();
错误代码:Parse error: syntax error, unexpected 'phpinfo' (T_STRING)
我想这不是啥问题,只是想知道它是为啥这样.如果直接重写覆盖会直接在函声明处产生一个致命错误,可是这里却能正常执行,而且直接覆盖掉了php内置方法(虽然不能正常输出),这应该不只是在5.4里面有,相信在其他版本里同样会有,是一个Bug吗??谢谢
另外,能不能给小弟我说说5.4版本的一些特性呢??
很久没敲php了,都有点生疏了,更别说是了解php的新特性了。。。。
再次感谢!
回复讨论(解决方案)
还有一个问题。
PHP Warning: PHP Startup: Invalid library (maybe not a PHP library) 'libmcrypt.dll' in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '../PHP/ext\php_iconv.dll' - 中包含无效路径
in Unknown on line 0
这个怎么解决?在UE中调用php.exe调试输出的,但是正常使用没有问题。。。。很郁闷的,DOS为什么会报错。。。。
(注:我自己配置的移动配置,之前有报错,把libmcrypt.dll和php_iconv.dll放到/Windows目录下可用,现在却又报错了,郁闷。。。。)
1.错误提示的很清楚了,估计是你的程序存有BOM头。 2.这是给$phpinfo赋值,所以要在行末加上分号来正确关闭。
3.错误提示给你的路径你看看对不对
第一个应该是bom头的问题
第二个只是定义了$phpinfo是一个匿名函数,和phpinfo()没有半毛钱关系,并没有覆盖掉phpinfo(),后面加上';' 就正常了
新特性支持以下语法:
//Short array syntax$a=[1,2,3,4,5,6];//Array dereferencingfunction foo(){ return array(1,2,3,4);}echo foo()[1];
还有Buid-in web server和Traits 楼下接着补充
确认问题一:确实是UTF-8的BOM头问题,已解决:
UE保存时采用格式为UTF-8 无BOM,搞定!
延伸问题二:后面引号去除可以正确调用,但是为啥引号不添加却不会报错??
我也碰到了问题一,不过我的是因为首行写了 `#! /bin/env php`
语言的变更很难三言两语讲完的,你最好查文档。
以下是我查的关于php从5.3到5.4的变更
http://www.php.net/manual/zh/migration54.php

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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

Following its high-profile acquisition by Facebook in 2012, Instagram adopted two sets of APIs for third-party use. These are the Instagram Graph API and the Instagram Basic Display API.As a developer building an app that requires information from a

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-

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

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' =>

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.

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

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
