我想知道是否可以键入提示方法以期望原始类型?
像这样的东西:
public function someMethod(string $str)
//^^^^^^
Run Code Online (Sandbox Code Playgroud)
要么:
private function anotherMethod(int $num)
//^^^
Run Code Online (Sandbox Code Playgroud)
你会这样:
private function otherMethod(Person $rambo)
//^^^^^^
Run Code Online (Sandbox Code Playgroud)
这可能在PHP吗?
root@ip-10-131-9-200:/etc/php5/apache2# php -a
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626+lfs/curl.so' - /usr/lib/php5/20090626+lfs/curl.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626+lfs/mcrypt.so' - /usr/lib/php5/20090626+lfs/mcrypt.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626+lfs/mysql.so' - /usr/lib/php5/20090626+lfs/mysql.so: cannot open shared object file: No such file or directory in …
Run Code Online (Sandbox Code Playgroud) 我为所有用户数据使用php会话(不是cookie,会话ID cookie除外),当用户访问他们的个人资料user.mydomain.com时,他们会立即"退出",直到删除子域.
有没有办法接受来自所有域的会话,只要它的*.mydomain.com
我有以下一段代码,我从模型中取出,
...
$select = $this->_db->select()
->from($this->_name)
->where('shipping=?',$type)
->where('customer_id=?',$userid);
echo $select; exit; // which gives exact mysql query.
.....
Run Code Online (Sandbox Code Playgroud)
当我在zend中使用更新查询时,
$up_value = array('billing'=> '0');
$this->update($up_value,'customer_id ='.$userid.' and address_id <> '.$data['address_Id']);
Run Code Online (Sandbox Code Playgroud)
在这里,我想知道确切的mysql查询.有没有办法在zend中打印mysql查询?好心劝告
__construct()
在PHP中使用构造函数代替类的名称是否有任何优势?
示例(__construct
):
class Foo {
function __construct(){
//do stuff
}
}
Run Code Online (Sandbox Code Playgroud)
示例(命名):
class Foo {
function Foo(){
//do stuff
}
}
Run Code Online (Sandbox Code Playgroud)
__construct
从PHP 5开始,可以使用该方法(第一个示例).
从PHP版本4到版本7,可以使用与类相同的方法作为构造函数(第二个示例).
我有一个字符串,我需要找出它是否是一个unix时间戳,我怎么能有效地做到这一点?
我通过谷歌找到了这个帖子,但我不敢提出一个非常可靠的答案.(是的,我在上述帖子的原始海报中提出了问题).
这必须简单,但我似乎无法找到答案....
我有一个$foo
没有属性的通用stdClass对象.我想为它添加一个$bar
尚未定义的新属性.如果我这样做:
$foo = new StdClass();
$foo->bar = '1234';
Run Code Online (Sandbox Code Playgroud)
PHP在严格模式下抱怨.
在已经实例化的对象中添加属性的正确方法(在类声明之外)是什么?
注意:我希望该解决方案与stdClass类型的通用PHP对象一起使用.
关于这个问题的一点背景.我正在解码一个json字符串,它是一个json对象数组. json_decode()
生成一个StdClass对象数组.我需要操纵这些对象并为每个对象添加属性.
我碰到SimpleXML对象转换为阵列的这种功能在这里:
/**
* function object2array - A simpler way to transform the result into an array
* (requires json module).
*
* This function is part of the PHP manual.
*
* The PHP manual text and comments are covered by the Creative Commons
* Attribution 3.0 License, copyright (c) the PHP Documentation Group
*
* @author Diego Araos, diego at klapmedia dot com
* @date 2011-02-05 04:57 UTC
* @link http://www.php.net/manual/en/function.simplexml-load-string.php#102277
* @license http://www.php.net/license/index.php#doc-lic
* @license http://creativecommons.org/licenses/by/3.0/ …
Run Code Online (Sandbox Code Playgroud) 我可以打电话curl_setopt
与CURLOPT_HTTPHEADER
多次设置多个标头?
$url = 'http://www.example.com/';
$curlHandle = curl_init($url);
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array('Content-type: application/xml'));
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array('Authorization: gfhjui'));
$execResult = curl_exec($curlHandle);
Run Code Online (Sandbox Code Playgroud) 如果我试试这个:
$a = 0;
echo $a + ++$a, PHP_EOL;
echo $a;
Run Code Online (Sandbox Code Playgroud)
我得到这个输出:
2
1
Run Code Online (Sandbox Code Playgroud)
演示:http://codepad.org/ncVuJtJu
我希望得到这个作为输出:
1
1
Run Code Online (Sandbox Code Playgroud)
$a = 0; // a === 0
echo $a + ++$a, PHP_EOL; // (0) + (0+1) === 1
echo $a; // a === 1
Run Code Online (Sandbox Code Playgroud)
但为什么输出不是这样呢?