SetTimestamp error – PHP 7.0.10
-
I am running WP 4.9.1 on WAMP server for testing. I have been using PHP Version 5.6.25 without a problem. I switched the PHP version to 7.0.10 to test before I upgrade the live site. When I edited a participant’s record, an error occurred after SUBMIT was clicked.
I looked at PDb_Date_Parse.class.php and participants-database.php but could not determine the reason for the error. I switched back to PHP version 5.6.25 and did the same edit without a problem.
_______
( ! ) Warning: DateTime::setTimestamp() expects parameter 1 to be integer, float given in C:\wamp\www\eltownhall.com\wp-content\plugins\participants-database\classes\PDb_Date_Parse.class.php on line 230
Call Stack
# Time Memory Function Location
1 0.0007 418128 {main}( ) …\admin.php:0
2 0.0010 432184 require_once( ‘C:\wamp\www\eltownhall.com\wp-load.php’ ) …\admin.php:31
3 0.0012 444992 require_once( ‘C:\wamp\www\eltownhall.com\wp-config.php’ ) …\wp-load.php:37
4 0.0018 533192 require_once( ‘C:\wamp\www\eltownhall.com\wp-settings.php’ ) …\wp-config.php:125
5 1.3987 54373880 do_action( ) …\wp-settings.php:471
6 1.3987 54374176 WP_Hook->do_action( ) …\plugin.php:453
7 1.3987 54374200 WP_Hook->apply_filters( ) …\class-wp-hook.php:310
8 1.4016 54722248 Participants_Db::process_page_request( ) …\class-wp-hook.php:286
9 1.4020 54724696 Participants_Db::process_form( ) …\participants-database.php:2576
10 1.4079 54825864 PDb_Date_Parse::timestamp( ) …\participants-database.php:1752
11 1.4080 54826576 PDb_Date_Parse->output( ) …\PDb_Date_Parse.class.php:87
12 1.4080 54826576 PDb_Date_Parse->parse_input( ) …\PDb_Date_Parse.class.php:148
13 1.4080 54826576 PDb_Date_Parse->intl_parse( ) …\PDb_Date_Parse.class.php:177
14 1.7669 54826904 setTimestamp ( )
…\PDb_Date_Parse.class.php:230
-
What is the date format you are using? Do you know what specific value it is trying to parse at that moment?
It’s possible PHP 7 is more strict about that argument, but I would need to know what value it was trying to handle to understand what’s happening.
I don’t know how to determine exactly which argument is causing the issue. If you can give me instructions, I will try to get you the answer.
—————————–
I have not setup any date fields of my own. The only date fields are the three that are found in the Record Information Fields tab. Those three fields display date/time stamps in this format: December 7, 2017 3:41 pm
Settings / Advanced Settings:
Strict Date Format is unchecked.
Input Date Format is: m/j/y——————————————–
I get the error when I click on Submit whether I have changed a field value or not.
These are what the date/time stamps look like in the database after I clicked Submit.
select date_recorded, date_updated, last_accessed from wp_participants_database where id=9
date_recorded date_updated last_accessed
2018-01-13 15:17:41 2018-01-13 15:17:41 2018-01-13 15:17:41This is the WordPress “debug.log”:
[13-Jan-2018 15:16:58 America/New_York] PDb_List_Admin::initialize list query= SELECT * FROM wp_participants_database p ORDER BY p.date_updated desc
[13-Jan-2018 15:17:41 America/New_York] PHP Warning: DateTime::setTimestamp() expects parameter 1 to be integer, float given in C:\wamp\www\eltownhall.com\wp-content\plugins\participants-database\classes\PDb_Date_Parse.class.php on line 230[13-Jan-2018 15:17:41 America/New_York] PHP Stack trace:
[13-Jan-2018 15:17:41 America/New_York] PHP 1. {main}() C:\wamp\www\eltownhall.com\wp-admin\admin.php:0
[13-Jan-2018 15:17:41 America/New_York] PHP 2. require_once() C:\wamp\www\eltownhall.com\wp-admin\admin.php:31
[13-Jan-2018 15:17:41 America/New_York] PHP 3. require_once() C:\wamp\www\eltownhall.com\wp-load.php:37
[13-Jan-2018 15:17:41 America/New_York] PHP 4. require_once() C:\wamp\www\eltownhall.com\wp-config.php:130
[13-Jan-2018 15:17:41 America/New_York] PHP 5. do_action() C:\wamp\www\eltownhall.com\wp-settings.php:471
[13-Jan-2018 15:17:41 America/New_York] PHP 6. WP_Hook->do_action() C:\wamp\www\eltownhall.com\wp-includes\plugin.php:453
[13-Jan-2018 15:17:41 America/New_York] PHP 7. WP_Hook->apply_filters() C:\wamp\www\eltownhall.com\wp-includes\class-wp-hook.php:310
[13-Jan-2018 15:17:41 America/New_York] PHP 8. Participants_Db::process_page_request() C:\wamp\www\eltownhall.com\wp-includes\class-wp-hook.php:286
[13-Jan-2018 15:17:41 America/New_York] PHP 9. Participants_Db::process_form() C:\wamp\www\eltownhall.com\wp-content\plugins\participants-database\participants-database.php:2576
[13-Jan-2018 15:17:41 America/New_York] PHP 10. PDb_Date_Parse::timestamp() C:\wamp\www\eltownhall.com\wp-content\plugins\participants-database\participants-database.php:1752
[13-Jan-2018 15:17:41 America/New_York] PHP 11. PDb_Date_Parse->output() C:\wamp\www\eltownhall.com\wp-content\plugins\participants-database\classes\PDb_Date_Parse.class.php:87
[13-Jan-2018 15:17:41 America/New_York] PHP 12. PDb_Date_Parse->parse_input() C:\wamp\www\eltownhall.com\wp-content\plugins\participants-database\classes\PDb_Date_Parse.class.php:148
[13-Jan-2018 15:17:41 America/New_York] PHP 13. PDb_Date_Parse->intl_parse() C:\wamp\www\eltownhall.com\wp-content\plugins\participants-database\classes\PDb_Date_Parse.class.php:177
[13-Jan-2018 15:17:41 America/New_York] PHP 14. DateTime->setTimestamp() C:\wamp\www\eltownhall.com\wp-content\plugins\participants-database\classes\PDb_Date_Parse.class.php:230
[13-Jan-2018 15:17:41 America/New_York] PHP Warning: DateTime::setTimestamp() expects parameter 1 to be integer, float given in C:\wamp\www\eltownhall.com\wp-content\plugins\participants-database\classes\PDb_Date_Parse.class.php on line 230
[13-Jan-2018 15:17:41 America/New_York] PHP Stack trace:
[13-Jan-2018 15:17:41 America/New_York] PHP 1. {main}() C:\wamp\www\eltownhall.com\wp-admin\admin.php:0
[13-Jan-2018 15:17:41 America/New_York] PHP 2. require_once() C:\wamp\www\eltownhall.com\wp-admin\admin.php:31
[13-Jan-2018 15:17:41 America/New_York] PHP 3. require_once() C:\wamp\www\eltownhall.com\wp-load.php:37
[13-Jan-2018 15:17:41 America/New_York] PHP 4. require_once() C:\wamp\www\eltownhall.com\wp-config.php:130
[13-Jan-2018 15:17:41 America/New_York] PHP 5. do_action() C:\wamp\www\eltownhall.com\wp-settings.php:471
[13-Jan-2018 15:17:41 America/New_York] PHP 6. WP_Hook->do_action() C:\wamp\www\eltownhall.com\wp-includes\plugin.php:453
[13-Jan-2018 15:17:41 America/New_York] PHP 7. WP_Hook->apply_filters() C:\wamp\www\eltownhall.com\wp-includes\class-wp-hook.php:310
[13-Jan-2018 15:17:41 America/New_York] PHP 8. Participants_Db::process_page_request() C:\wamp\www\eltownhall.com\wp-includes\class-wp-hook.php:286
[13-Jan-2018 15:17:41 America/New_York] PHP 9. Participants_Db::process_form() C:\wamp\www\eltownhall.com\wp-content\plugins\participants-database\participants-database.php:2576
[13-Jan-2018 15:17:41 America/New_York] PHP 10. PDb_Date_Parse::timestamp() C:\wamp\www\eltownhall.com\wp-content\plugins\participants-database\participants-database.php:1752
[13-Jan-2018 15:17:41 America/New_York] PHP 11. PDb_Date_Parse->output() C:\wamp\www\eltownhall.com\wp-content\plugins\participants-database\classes\PDb_Date_Parse.class.php:87
[13-Jan-2018 15:17:41 America/New_York] PHP 12. PDb_Date_Parse->parse_input() C:\wamp\www\eltownhall.com\wp-content\plugins\participants-database\classes\PDb_Date_Parse.class.php:148
[13-Jan-2018 15:17:41 America/New_York] PHP 13. PDb_Date_Parse->intl_parse() C:\wamp\www\eltownhall.com\wp-content\plugins\participants-database\classes\PDb_Date_Parse.class.php:177
[13-Jan-2018 15:17:41 America/New_York] PHP 14. DateTime->setTimestamp() C:\wamp\www\eltownhall.com\wp-content\plugins\participants-database\classes\PDb_Date_Parse.class.php:230
[13-Jan-2018 15:17:41 America/New_York] Participants_Db::process_form storing record: UPDATE wp_participants_database SET
date_updated
= NOW(),first_name
= ‘Testfirstname’,last_name
= ‘Testlastname’,birth_year
= ‘1960’,address
= ‘1 Post Road’,city
= ‘Mycityname’,state
= ‘XX’,zip
= ‘12345’,phone
= ‘9998764321’,email
= ‘[email protected]’,verify_email_address
= ‘[email protected]’,mailing_list
= ‘Yes’,skills
= ‘a:5:{i:1;s:20:\”computer programming\”;i:2;s:5:\”excel\”;i:3;s:10:\”powerpoint\”;i:4;s:15:\”web development\”;i:5;s:4:\”word\”;}’,skill_level
= ‘expert’,interests
= ‘a:6:{i:1;s:20:\”computer programming\”;i:2;s:10:\”data entry\”;i:3;s:5:\”excel\”;i:4;s:10:\”powerpoint\”;i:5;s:15:\”web development\”;i:6;s:4:\”word\”;}’,day_of_week
= ‘a:5:{i:1;s:6:\”monday\”;i:2;s:7:\”tuesday\”;i:3;s:9:\”wednesday\”;i:4;s:8:\”thursday\”;i:5;s:6:\”friday\”;}’,time_of_day
= ‘a:3:{i:1;s:7:\”morning\”;i:2;s:9:\”afternoon\”;i:3;s:7:\”evening\”;}’,volunteer_at
= ‘a:1:{i:1;s:4:\”town\”;}’,approved
= ‘yes’,assigned_areas
= ‘a:2:{i:1;s:22:\”information technology\”;i:2;s:13:\”senior center\”;}’,date_recorded
= ‘2018-01-13 15:17:41’,last_accessed
= ‘2018-01-13 15:17:41’ WHERE id = 9[13-Jan-2018 15:17:41 America/New_York] PHP Warning: Cannot modify header information – headers already sent by (output started at C:\wamp\www\eltownhall.com\wp-content\plugins\participants-database\classes\PDb_Date_Parse.class.php:230) in C:\wamp\www\eltownhall.com\wp-includes\pluggable.php on line 1216
[13-Jan-2018 15:17:41 America/New_York] PHP Stack trace:
[13-Jan-2018 15:17:41 America/New_York] PHP 1. {main}() C:\wamp\www\eltownhall.com\wp-admin\admin.php:0
[13-Jan-2018 15:17:41 America/New_York] PHP 2. require_once() C:\wamp\www\eltownhall.com\wp-admin\admin.php:31
[13-Jan-2018 15:17:41 America/New_York] PHP 3. require_once() C:\wamp\www\eltownhall.com\wp-load.php:37
[13-Jan-2018 15:17:41 America/New_York] PHP 4. require_once() C:\wamp\www\eltownhall.com\wp-config.php:130
[13-Jan-2018 15:17:41 America/New_York] PHP 5. do_action() C:\wamp\www\eltownhall.com\wp-settings.php:471
[13-Jan-2018 15:17:41 America/New_York] PHP 6. WP_Hook->do_action() C:\wamp\www\eltownhall.com\wp-includes\plugin.php:453
[13-Jan-2018 15:17:41 America/New_York] PHP 7. WP_Hook->apply_filters() C:\wamp\www\eltownhall.com\wp-includes\class-wp-hook.php:310
[13-Jan-2018 15:17:41 America/New_York] PHP 8. Participants_Db::process_page_request() C:\wamp\www\eltownhall.com\wp-includes\class-wp-hook.php:286
[13-Jan-2018 15:17:41 America/New_York] PHP 9. wp_redirect() C:\wamp\www\eltownhall.com\wp-content\plugins\participants-database\participants-database.php:2668
[13-Jan-2018 15:17:41 America/New_York] PHP 10. header() C:\wamp\www\eltownhall.com\wp-includes\pluggable.php:1216
————————————————————–
I noticed that the record it fails on has date/time stamp values in all three Record Information Fields.
I have several records where the Date recorded and the Last Accessed fields are empty and remain empty after clicking Submit. I do not get the error when updating these records.
select date_recorded, date_updated, last_accessed from wp_participants_database where id=21
date_recorded date_updated last_accessed
2018-01-13 15:01:14I think it should be updating date_recorded and last_accessed, too. But, that is probably a different problem.
I added some logging code.
Before Line 1752 in participants-database.php, I added:
if( WP_DEBUG ){ $mymessage=$column->name . ":" . $post[$column->name]; my_log_file($mymessage ); }
At the end of participants-database.php, I added:
function my_log_file( $msg, $name = '' ) { // Print the name of the calling function if $name is left empty $trace=debug_backtrace(); $name = ( '' == $name ) ? $trace[1]['function'] : $name; $error_dir = 'C:\wamp\logs\php_error.log'; $msg = print_r( $msg, true ); $log = $name . " | " . $msg . "\n"; error_log( $log, 3, $error_dir ); }
This was in the log file after getting the error:
process_form | date_recorded:January 13, 2018 4:55 pm process_form | last_accessed:January 13, 2018 4:55 pm
Does this help?
If you want more variables displayed, please let me know which ones and where in the php files.
This may help. I added some logging into PDb_Date_Parse.class.php.
process_form | date_recorded:January 13, 2018 5:35 pm timestamp | Parameters to new self() timestamp | input:January 13, 2018 5:35 pm timestamp | context:Participants_Db::process_form saving timestamps output | In function output() output | this->timestamp: parse_input | In function parse_input() parse_input | this->input:January 13, 2018 5:35 pm intl_parse | In function intl_parse() intl_parse | timestamp:-210866353438 process_form | last_accessed:January 13, 2018 5:35 pm timestamp | Parameters to new self() timestamp | input:January 13, 2018 5:35 pm timestamp | context:Participants_Db::process_form saving timestamps output | In function output() output | this->timestamp: parse_input | In function parse_input() parse_input | this->input:January 13, 2018 5:35 pm intl_parse | In function intl_parse() intl_parse | timestamp:-210866353438
I wonder if timestamp as a negative number is the isue?
Thanks this is helpful.
Negative timestamps are common, any date before 1970 will be a negative number, but clearly the date is not that.
Really, I just need to check the value before trying to parse it. Thanks for your help with this, I’ll post a fix soon.
Thanks. Maybe it’s related to the problem where some of my records have empty date_recorded and last_accessed fields no matter how many times I update those records.
You using the latest Participants Database?
So far, I can’t duplicate the issue, I don’t know how a floating point value gets in there. Of course, the warning can be avoided by usgin something like this on the affected line:
$the_Date->setTimestamp( (int) $timestamp );
or you can ignore it since it’s not causing any real problems. I’ll keep this in the bug list in case I figure out what causes it.
My Participants Database plugin is Version 1.7.7.3.
$the_Date->setTimestamp( (int) $timestamp );
Using int() caused both date_recorded and date_accessed to be set to empty in the database after clicking the Submit button.
As reported yesterday, there are other records where date_recorded and date_accessed have been empty and remain empty after clicking Submit to update the record.
When I revert to PHP 5.6.25, date_recorded and date_accessed remain empty after clicking Submit to update a record.
OK, so the real problem here is why are your records getting written with blank timestamps.
If you’ve got your PHP error log set up, and running with WP_DEBUG, the plugin will log the query used to store a record. Take a look at that and maybe post it here.
Thanks for your help in resolving this issue.
I found where the date_recorded and date_accessed are getting set to empty when a record is updated. Because the database value for date_recorded and date_accessed is empty, it falls into an else block where it re-uses the empty value.
Before I can resume debugging/testing with PHP 7.0.10, this issue needs to be corrected. All of my records currently have empty date_recorded and date_accessed columns so none of them trigger the issue first reported with PHP 7.0.10.
See the “At this point it assigns an empty value to $new_value” note in the PHP code below.
Debug Log:
process_form | Column Name date_recorded= is_mysql_timestamp | is_mysql_timestamp() return value=1 process_form | !PDb_Date_Parse::is_mysql_timestamp(post[column->name] is false - saved value used= process_form | Column Name last_accessed= is_mysql_timestamp | is_mysql_timestamp() return value=1 process_form | !PDb_Date_Parse::is_mysql_timestamp(post[column->name] is false - saved value used=
participants-database.php within process_form():
case 'date_recorded': case 'date_updated': case 'last_accessed': /** * skip the "last_accessed" field if the record is newly created */ if ( $column->name === 'last_accessed' && $action !== 'update' ) { $new_value = false; break; } /* * remove the value from the post data if it is already set in the sql */ if ( strpos( $sql, $column->name ) !== false ) { unset( $post[$column->name] ); $new_value = false; break; } /** * @version 1.7.0.15 * * if the localized timestamp date strings can't be parsed normally, we use the saved value if available */ my_log_file("Column Name " . $column->name . "=" . $post[$column->name]); if ( !PDb_Date_Parse::is_mysql_timestamp( $post[$column->name] ) ) { $new_value = ''; $display_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' ); my_log_file("display_format=" . $display_format); $timestamp = PDb_Date_Parse::timestamp( $post[$column->name], array('input_format' => $display_format), __METHOD__ . ' saving timestamps' ); if ( $timestamp ) { $new_value = PDb_Date_Display::get_mysql_timestamp( $timestamp ); } else { // try using the saved value $saved = is_numeric( $participant_id ) ? self::get_participant( $participant_id ) : false; // use the saved value if available so we don't have to try to parse the string back to a mysql timestamp if ( $saved && isset( $saved[$column->name] ) && PDb_Date_Parse::is_mysql_timestamp( $saved[$column->name] ) ) { $new_value = $saved[$column->name]; my_log_file("If timestamp is false, saved value used=" . $saved[$column->name]); } else { my_log_file("If timestamp is false, no saved value used"); } } } else { my_log_file("!PDb_Date_Parse::is_mysql_timestamp(post[column->name] is false - saved value used=" . $post[$column->name]); /* <strong>At this point it assigns an empty value to $new_value</strong> */ $new_value = $post[$column->name]; } break;
This show the initial signup creates the date_recorded and last_accessed as empty and they remain empty upon subsequent updates. Immediately after the initial signup page was submitted, I used the pencil icon on the List Participants page to edit the record.
**** Debug log for initial signup ****
[14-Jan-2018 13:47:59 America/New_York] Participants_Db::process_form storing record: INSERT INTO wp_participants_database SET
first_name= 'TestFirstname',
last_name= 'TestLastNameX',
birth_year= '1978',
phone= '9999999999',
email= '[email protected]',
verify_email_address= '[email protected]',
mailing_list= 'Yes',
private_id= 'ELY1WC2CUPUERM5GNEGOA5VFGMFBFPSC8T38LNVQSAGD970KXETDCI7EH3RT',
city= 'Xxxxxxx',
state= 'XX',
zip= '99999',
approved= 'no',
skill_level` = ‘Some’[14-Jan-2018 13:48:02 America/New_York] xnau_Template_Email::_mail
context: PDb_Signup::_do_notify
header: From: xxxxx <[email protected]>
Content-Type: text/html; charset=”UTF-8″
X-Generator: Participants Databaseto: [email protected]
attachments: Array
(
)subj.: New signup for Volunteer Database
message:
<p>A new signup has been submitted</p>
<ul>
<li>Name: TestFirstname TestLastNameX</li>
<li>Email: [email protected]</li>
</ul>
<p>Edit this new record here: <a href=”https://eltownhall.com/wp-admin/admin.php?page=participants-database-edit_participant&action=edit&id=22″>https://xxxxxxxxx.com/wp-admin/admin.php?page=participants-database-edit_participant&action=edit&id=22</a></p>[14-Jan-2018 13:48:04 America/New_York] xnau_Template_Email::_mail sending failed for: [email protected] while doing: PDb_Signup::_do_notify
[14-Jan-2018 13:48:04 America/New_York] xnau_Template_Email::_mail
context: PDb_Signup::_do_receipt
header: From: xxxxx <[email protected]>
Content-Type: text/html; charset=”UTF-8″
X-Generator: Participants Databaseto: [email protected]
attachments: Array
(
)subj.: Volunteer Database
message:
<p>Thank you, TestFirstname, for registering in the xxxxxxx.</p>
<p>You may complete your registration with additional information or update your information by visiting this private link at any time: <a href=”https://eltownhall.com/community/volunteer-corps/volunteer-record/?pid=ELY1WC2CUPUERM5GNEGOA5VFGMFBFPSC8T38LNVQSAGD970KXETDCI7EH3RT”>https://eltownhall.com/community/volunteer-corps/volunteer-record/?pid=ELY1WC2CUPUERM5GNEGOA5VFGMFBFPSC8T38LNVQSAGD970KXETDCI7EH3RT</a>. Be sure to save the private link so that you can make changes to your volunteer profile at a later time.</p>
<p><strong>WARNING: DO NOT FORWARD THIS EMAIL MESSAGE.</strong></p>`**** Note: After initial signup, date_recorded, Date_updated, last_accessed are empty ****
*** Debug log for Submit when editing the new record ****
*** Immediately after the initial signup page was submitted, I used the pencil icon on the List Participants page to edit the record ***[14-Jan-2018 13:53:58 America/New_York] PDb_List_Admin::initialize list query= SELECT * FROM wp_participants_database p ORDER BY p.date_updated desc [14-Jan-2018 13:55:40 America/New_York] Participants_Db::process_form storing record: UPDATE wp_participants_database SET <code>date_updated</code> = NOW(), <code>first_name</code> = 'TestFirstname', <code>last_name</code> = 'TestLastNameX', <code>birth_year</code> = '1978', <code>address</code> = '', <code>city</code> = 'East Lyme', <code>state</code> = 'CT', <code>zip</code> = '06333', <code>phone</code> = '8609999999', <code>email</code> = '[email protected]', <code>verify_email_address</code> = '[email protected]', <code>mailing_list</code> = 'Yes', <code>skills</code> = '', <code>interests</code> = '', <code>day_of_week</code> = '', <code>time_of_day</code> = '', <code>volunteer_at</code> = '', <code>approved</code> = 'no', <code>assigned_areas</code> = '', <code>date_recorded</code> = '', <code>last_accessed</code> = '' WHERE id = 22 [14-Jan-2018 13:55:42 America/New_York] PDb_List_Admin::initialize list query= SELECT * FROM wp_participants_database p ORDER BY p.date_updated desc
**** Note: After Submit when editing the record, date_recorded and last_accessed are empty ****
Thanks for your persistence. It looks like there is a bug that happens when using PHP7 where the previously saved timestamp value is not parsed correctly, and so a zero value gets saved.
I will need to issue a bug fix for this.
I want to be sure that you understand that the last test above was done on PHP 5.6.25 and not PHP 7.0.10. In that test, the initial signup transaction leaves date_recorded and last_accessed empty and the record update done via the pencil icon on the List Participants page retains the empty values for date_recorded and last_accessed.
When this issue is fixed, I can resume testing with PHP 7.0.10.
- The topic ‘SetTimestamp error – PHP 7.0.10’ is closed to new replies.