简体   繁体   English

如何解决致命错误“在第865行上的/xyz/pqr/prj_name/functions/common.php中的非对象上调用成员函数format()”?

[英]How to resolve the fatal error “Call to a member function format() on a non-object in /xyz/pqr/prj_name/functions/common.php on line 865”?

Following is the necessary code from file " /xyz/pqr/prj_name/functions/common.php " 以下是文件“ /xyz/pqr/prj_name/functions/common.php ”中的必要代码

function format_date_yyyy_mm_dd($date_val) {
  $date = DateTime::createFromFormat('n-j-Y', $date_val);
  return $date->format('Y-m-d');  //Thie is line no.865 where I'm getting the error.
}

This file has been included into the file where the function format_date_yyyy_mm_dd() is called. 该文件已包含在调用format_date_yyyy_mm_dd()函数的文件中。

The code for calling the function is as follows : 调用该函数的代码如下:

$form_data['reg_date'] = format_date_yyyy_mm_dd($form_data['reg_date']);

Can some one please help in correcting the code I've written and help me where my code is going wrong? 有人可以帮忙纠正我编写的代码,并帮我解决我的代码出问题的地方吗?

Thanks in advance. 提前致谢。

You code is correct, please check the value of $form_data['reg_date'] and make sure it is something like 12-19-2014 and it should be month-date-year . 您输入的代码正确无误,请检查$form_data['reg_date']的值,并确保该值类似于12-19-2014 ,并且应为month-date-year You may passing wrong format of date from your form. 您可能从表格中传递了错误的日期格式。

echo format_date_yyyy_mm_dd('12-19-2014');

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHP:致命错误在非对象上调用成员函数format() - PHP :Fatal error Call to a member function format() on a non-object 致命错误:在非对象上调用成员函数format() - Fatal error: Call to a member function format() on a non-object Drupal:致命错误:调用非对象上的成员函数 format() - Drupal: Fatal error: Call to a member function format() on a non-object 致命错误:在非对象中调用成员函数format() - Fatal error: Call to a member function format() on a non-object in 致命错误:在非对象上调用成员函数format() - Fatal error: Call to a member function format() on a non-object 致命错误:在第 72 行调用 C:\\wamp\\www\\test\\functions.php 中非对象的成员函数 fetchAll() - Fatal error: Call to a member function fetchAll() on a non-object in C:\wamp\www\test\functions.php on line 72 致命错误:在第413行的/functions.php中的非对象上调用成员函数get_cart_contents_count() - Fatal error: Call to a member function get_cart_contents_count() on a non-object in /functions.php on line 413 PHP致命错误:在非对象上调用成员函数asXML() - PHP fatal error: Call to a member function asXML() on a non-object 致命错误:在PHP中的非对象上调用成员函数execute() - Fatal error: Call to a member function execute() on a non-object in php PHP:捕获致命错误(调用非对象上的成员函数) - PHP: catching a fatal error (call to member function on a non-object)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM