Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP:未正确传递_构造的字符串参数_Php_Tdd_Instantiation_Parameter Passing - Fatal编程技术网

PHP:未正确传递_构造的字符串参数

PHP:未正确传递_构造的字符串参数,php,tdd,instantiation,parameter-passing,Php,Tdd,Instantiation,Parameter Passing,我正在用PHP尝试TDD,并且正在编写一个基于Web的应用程序来访问MySQL数据库中的文章;这是测试功能: class TestArticleTestCase extends UnitTestCase { ... public function testArticleGenerateInsertSqlString() { $testArticle = new Article("12345", "2009-09-13 20:20:20", "Test heading", "Test

我正在用PHP尝试TDD,并且正在编写一个基于Web的应用程序来访问MySQL数据库中的文章;这是测试功能:

class TestArticleTestCase extends UnitTestCase {

...

public function testArticleGenerateInsertSqlString() {
    $testArticle = new Article("12345", "2009-09-13 20:20:20", "Test heading", "Test text");

    ...

}
这是文章类:

class Article {
    private $_articleId;
    private $_pubDate;
    private $_heading;
    private $_text;

    public function __construct($articleId, $pubDateUnchecked, $headingUnescaped, $textUnescaped) {
        echo "pubDateUnchecked == $pubDateUnchecked </BR>";
            ...

 }
我将echo包含在构造函数中,因为数据库中的日期不是我初始化文章时使用的日期,而且可以肯定的是,跟踪问题,这是构造函数中该echo的输出:

pubDateUnchecked==2005-06-01 12:00:00

也许我只是盯着这段代码看得太久了,但是字符串怎么能从我实例化它的地方变为直接实例化它的地方呢,在我开始将它作为一个日期来操作之前,我检查它是否是一个允许的日期格式,并在以后使用strotime和date

有人知道去哪里找吗

谢谢,,
斯蒂芬。

可能是缓存问题?或者你编辑了错误的文件?以前发生过- 在这种情况下,调试器会很有帮助。但是,如果您没有/无法安装,请尝试以下操作

public function testArticleGenerateInsertSqlString() {
  $testdata = array(
    array('articleId'=>"12345", 'pubDateUnchecked'=>"2009-09-13 20:20:20", 'headingUnescaped'=>"Test heading", 'textUnescaped'=>"Test text")
  );
  echo '<div>Test. Now=', date('Y-m-d H:i:s'),' modtime(__FILE__)=', date('Y-m-d H:i:s', filemtime(__FILE__)), "</div>\n";
  foreach( $testdata as $t ) {
    echo "<div>Test. new Article({$t['articleId']}, {$t['pubDateUnchecked']}, {$t['headingUnescaped']}, {$t['textUnescaped']})</div>";
    $testArticle = new Article($t['articleId'], $t['pubDateUnchecked'], $t['headingUnescaped'], $t['textUnescaped']); 

你确定?我看不出这段代码有任何错误,非常感谢您编写的测试代码VolkerK!我运行了它,发现如果$timestamp=strotime$pubDateUnchecked==false{throw new Exception'Invalid pubDate.Date必须是例如YYYY-MM-DD H:M:S';},那么问题就出在行中,该行始终生成1970-01-01 02:00:00。围绕着任务,他解决了问题。。丹基!