在CodeIgniter的文档中,它指出,
建议使用PHP 5.4或更高版本.
我在论坛等上查看并且无法在此找到明确的是/否,即使上面的句子暗示'是',我也不确定是否扩展到(现在是新的)PHP7.
我用PHP7尝试了一个简单的CI3示例,到目前为止,我所能报告的内容都非常好.
我试图重现这个基准测试,它将PHP 7与旧版本在Wordpress服务器上进行比较:http://talks.php.net/oz15#/wpbench
我的配置几乎相同,服务器有i7,SSD,16GB RAM和debian.服务器软件是nginx.令人惊讶的是,我的结果与上面提到的结果有很大不同.
在我的测试中,Siege(https://www.joedog.org/siege-home/)输出以下内容:
对于PHP 7.0.0RC1:
siege -c100 -r100 http://10.22.255.133/wordpress/
** SIEGE 3.0.8
** Preparing 100 concurrent users for battle.
The server is now under siege.. done.
Transactions: 10000 hits
Availability: 100.00 %
Elapsed time: 131.61 secs
Data transferred: 95.77 MB
Response time: 0.75 secs
Transaction rate: 75.98 trans/sec
Throughput: 0.73 MB/sec
Concurrency: 56.98
Successful transactions: 10000
Failed transactions: 0
Longest transaction: 1.01
Shortest transaction: 0.04
Run Code Online (Sandbox Code Playgroud)
对于PHP 5.6.12:
siege -c100 -r100 http://10.22.255.133/wordpress/
** SIEGE …Run Code Online (Sandbox Code Playgroud) 将Ubuntu从14.04升级到16.04后,PHP CLI开始抱怨xdebug:
$ php -v
Cannot load Xdebug - it was already loaded
PHP 7.0.13-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.13-0ubuntu0.16.04.1, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans
Run Code Online (Sandbox Code Playgroud)
只有一个.ini文件:
$ ls -la /etc/php/7.0/cli/conf.d/ | grep xdebug
lrwxrwxrwx 1 root root 38 Jan 19 11:41 20-xdebug.ini -> /etc/php/7.0/mods-available/xdebug.ini
Run Code Online (Sandbox Code Playgroud)
它只在以下输出中引用一次php -i:
$ php -i | grep …Run Code Online (Sandbox Code Playgroud) 是否可以在Debian 9上的Apache 2.4中同时运行PHP 7和PHP 5?我希望能够选择我希望每个虚拟主机使用的PHP版本.我相信考虑到我的一些网站仍然使用弃用的PHP功能,这将是有用的.这允许我对每个站点执行升级.我如何实现这样的目标?
例如
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName mywebsite.com
DocumentRoot /var/www/mywebsite.com
# UsePHP 7
</virtualHost>
Run Code Online (Sandbox Code Playgroud)
和
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName mywebsite2.com
DocumentRoot /var/www/mywebsite2.com
# UsePHP 5
</virtualHost>
Run Code Online (Sandbox Code Playgroud) 我在php7中有返回类型的问题,特别是"void".
它适用于所有其他类型,int,string,null,bool,类对象.
但是当我使用void时,它希望我返回一个对象void的实例,但实际上它不应该指望任何返回,因为那是什么空虚.
注意:我正在运行PHP 7.0.3
这是代码:
public static function setResponseCode(int $code) : void
{
http_response_code($code);
}
Run Code Online (Sandbox Code Playgroud)
和错误消息是:
未捕获的TypeError:CodeBase的返回值\ HttpRequester :: setResponseCode()必须是void的实例,在/var/www/html/src/HttpRequester.php:86中返回无堆栈跟踪:#0/var/www/html/index.php(103):CodeBase\HttpRequester :: setResponseCode(500)在第86行的/var/www/html/src/HttpRequester.php中抛出#1 {main}
我正在使用Symfony 3.1和Doctrine 2.5.
我像往常一样设置了很多ToMany关系:
manyToMany:
placeServices:
targetEntity: Acme\MyBundle\Entity\PlaceService
joinTable:
name: place_place_service
joinColumns:
place_id:
referencedColumnName: id
inverseJoinColumns:
place_service_id:
referencedColumnName: id
Run Code Online (Sandbox Code Playgroud)
并向我的实体添加方法
protected $placeServices;
...
public function __construct()
{
$this->placeServices = new ArrayCollection();
}
...
/**
* @return ArrayCollection
*/
public function getPlaceServices(): ArrayCollection
{
return $this->placeServices;
}
/**
* @param PlaceServiceInterface $placeService
* @return PlaceInterface
*/
public function addPlaceService(PlaceServiceInterface $placeService): PlaceInterface
{
if(!$this->placeServices->contains($placeService)) {
$this->placeServices->add($placeService);
}
return $this;
}
/**
* @param PlaceServiceInterface $placeService
* @return PlaceInterface
*/
public function removePlaceService(PlaceServiceInterface …Run Code Online (Sandbox Code Playgroud) 我确信这是预期的行为array_column():
class myObj {
public $prop;
public function __construct(int $prop) {
$this->prop = $prop;
}
}
$objects = [
new myObj(7),
new myObj(3),
new myObj(8),
new myObj(0),
new myObj(2),
new myObj(6)
];
echo '<pre>';
print_r(array_column($objects, 'prop'));
echo '</pre>';
Run Code Online (Sandbox Code Playgroud)
返回:
Array (
[0] => 7
[1] => 3
[2] => 8
[3] => 2
[4] => 6
)
Run Code Online (Sandbox Code Playgroud)
的0缺失.也许它在empty()内部使用..?
为什么它不会返回有价值的值,0并且false可以是正常的有效对象属性值,并且array_column()用于返回值..?
什么是最好的工作...?
所以我知道我可以在php7中做返回类型提示.我可以做一个对象返回提示:
function getUser($pdo, $username) : User
{
}
Run Code Online (Sandbox Code Playgroud)
其中User是要返回的对象.
但是,如果在SQL中找不到用户,则返回'false'而不是User对象给出:
未捕获的TypeError:UserFind :: findUser()的返回值必须是User的实例,返回布尔值
但是如果SQL无法找到用户怎么办?如果用户不存在,我怎么能返回一个布尔值false?在这种情况下,我应该忽略返回类型提示吗?
编辑:我看了另一个问题,"在PHP 7中可以为Nullable返回类型",虽然我的问题几乎相同,但我想通过询问是否有办法返回两种类型中的一种来扩展我的问题.例如,如果对象不存在,则返回一个对象或一个字符串?
我已经从ubuntu卸载了php7及其所有模块,当我尝试重新安装模块时,我得到每个php模块的以下错误,虽然模块已安装,但由于此错误,它未激活且我无法使用他们.有什么方法可以解决这个问题吗?每个模块的错误(安装时):
Not replacing deleted config file /etc/php/7.0/mods-available/intl.ini
WARNING: Module [module name] ini file doesn't exist under /etc/php/7.0/mods-available
WARNING: Module [module name] ini file doesn't exist under /etc/php/7.0/mods-available
WARNING: Module [module name] ini file doesn't exist under /etc/php/7.0/mods-available
Run Code Online (Sandbox Code Playgroud) 正如php.net所示: random_int() function 生成加密安全的伪随机整数.
但是,有人可以解释一下rand()&之间的区别random_int()吗?我可以使用random_int()而不是rand()只需要一个随机整数吗?哪一个更快?
php-7 ×10
php ×8
type-hinting ×2
apache ×1
codeigniter ×1
debian ×1
doctrine-orm ×1
mysql ×1
nginx ×1
return-type ×1
symfony ×1
virtualhost ×1
wordpress ×1
xdebug ×1