Skip to content

Add __wakeup method to Time #3557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 29, 2020
Merged

Add __wakeup method to Time #3557

merged 2 commits into from
Aug 29, 2020

Conversation

paulbalandan
Copy link
Member

Description
Fixes #3553

Little side note on __wakeup().

  • Simple fix for the problem is just provide an empty __wakeup method to Time for the sake of overriding DateTime::__wakeup(). However, with that, we cannot initialize the parent, DateTime. With this fix, we can get an "equal" Time object (but not the "same" since they are not referencing to the same object).

Continuing on the controller code:

        public function index()
	{
		// return view('welcome_message');

		$web = new Web();
		$web->url = 123;
		$web->created_at = date('Y-m-d H:i:s');
		var_dump($web->created_at);

		$cache = Services::cache();
		$cache->save('webname', $web, 300);

		$web = $cache->get('webname');
		var_dump($web->created_at);
	}

we will get this:

C:\Users\P\Desktop\Web Dev\CodeIgniter4\app\Controllers\Home.php:15:
object(CodeIgniter\I18n\Time)[65]
  protected 'timezone' => 
    object(DateTimeZone)[66]
      public 'timezone_type' => int 3
      public 'timezone' => string 'America/Chicago' (length=15)
  protected 'locale' => string 'en' (length=2)
  protected 'toStringFormat' => string 'yyyy-MM-dd HH:mm:ss' (length=19)
  public 'date' => string '2020-08-28 10:35:45.000000' (length=26)
  public 'timezone_type' => int 3
  public 'timezone' => string 'America/Chicago' (length=15)

C:\Users\P\Desktop\Web Dev\CodeIgniter4\app\Controllers\Home.php:21:
object(CodeIgniter\I18n\Time)[68]
  protected 'timezone' => 
    object(DateTimeZone)[69]
      public 'timezone_type' => int 3
      public 'timezone' => string 'America/Chicago' (length=15)
  protected 'locale' => string 'en' (length=2)
  protected 'toStringFormat' => string 'yyyy-MM-dd HH:mm:ss' (length=19)
  public 'date' => string '2020-08-28 10:35:45.000000' (length=26)
  public 'timezone_type' => int 3
  public 'timezone' => string 'America/Chicago' (length=15)

Checklist:

  • Securely signed commits
  • Component(s) with PHPdocs
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@michalsn michalsn merged commit b031a3b into codeigniter4:develop Aug 29, 2020
@paulbalandan paulbalandan deleted the time-unserialize branch August 29, 2020 10:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Invalid serialization data for DateTime object
2 participants