This is a collection of questions that come up every now and then about syntax in PHP. This is also a Community Wiki, so everyone is invited to participate in maintaining this list.
It used to be hard to find questions about operators and other syntax tokens.¹
The main idea is to have links to existing questions on Stack Overflow, so it's easier for us to reference them, not to copy over content from …
我刚刚看到在PHP对象的引用中使用了反斜杠,并对此感到好奇(我以前从未见过这个).这是什么意思?
$mail = new SendGrid\Mail();
Run Code Online (Sandbox Code Playgroud)
如果你很好奇,这里是SendGrid的文档.
这是一个测试代码:
<?php
ini_set('date.timezone', 'Europe/London');
$dt = new \DateTime('0000-00-00 00:00:00');
var_dump($dt);
Run Code Online (Sandbox Code Playgroud)
这提供:
object(DateTime)[1]
public 'date' => string '-0001-11-30 00:00:00' (length=20)
public 'timezone_type' => int 3
public 'timezone' => string 'Europe/London' (length=13)
Run Code Online (Sandbox Code Playgroud)
而这不是有效日期.我不明白返回的价值,特别是月份......你能解释一下吗?
需要你在一个不寻常的情况下提供帮助.我需要修剪所有$ _POST变量.
有什么方法可以一次性完成,即使用单一功能吗?
我知道修剪($ _ POST)不会做,我必须做一些功能
function sanatize_post(){
foreach ($_POST as $key => $val)
$_POST[$key] = trim($val);
}
Run Code Online (Sandbox Code Playgroud)
但是,如果您有任何其他建议或评论,请帮助我.
谢谢
准备ZEND-Exam时,我发现了一个类重新定义了strlen-function的问题:
namespace MyFramework\MyString
{
function strlen ($str)
{
return \strlen($str) * 2; // return double string-length
}
}
Run Code Online (Sandbox Code Playgroud)
我之前从来没有遇到过"\功能"的东西,也无法从我的教练那里得到解释 - 有人可以.帮助摆脱一些光......?
为什么 PHP 中的命名空间使用反斜杠 () 来分隔文件夹?
例如:
namespace Core\fruit\Apple;
Run Code Online (Sandbox Code Playgroud)
这其中有什么特别的原因吗?
我觉得反斜杠约定不合逻辑,因为 unix/linux 文件系统使用正斜杠。但我的观点不是重点。
一个简短而简单的问题,我无法真正找到答案.
在程序PHP中我可以回复一个日期
echo date('Y-m-d'); ?>
Run Code Online (Sandbox Code Playgroud)
在面向对象的PHP中,我必须使用两行
$now = new DateTime();
echo $now->format('Y-m-d');
Run Code Online (Sandbox Code Playgroud)
有可能在一行中完成吗?
为什么这行Symfony代码之前有反斜杠DateTime()?
$this->updated_datetime = new \DateTime();
Run Code Online (Sandbox Code Playgroud)
我很确定这与NameSpaces有关,但有人可以确认/澄清......
是什么区别(Exception $e)和(\Exception $e)在try{}catch(){}
什么是“反斜杠\”前的影响Exception?
require和require_once中的路径类似于(dir1/dir2/test.php).
我们可以创建相同的对象$obj= new class1/class2;吗?
如果是,请解释.
http://php-fedex-api-wrapper.googlecode.com/svn/trunk/htdocs/example1.php
$rateRequest = new ComplexType\RateRequest();
Run Code Online (Sandbox Code Playgroud)