Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3458534
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:59:40+00:00 2026-05-18T09:59:40+00:00

I saw this phrase in the PHPUnit Documentation: The implementation of the backup and

  • 0

I saw this phrase in the PHPUnit Documentation:

The implementation of the backup and
restore operations for static
attributes of classes requires PHP 5.3
(or greater). The implementation of
the backup and restore operations for
global variables and static attributes
of classes uses serialize() and
unserialize()

What is the idea behind this? I mean, I haven’t used serialize and unserialize for this purpose. How exactly are these so-called “backup and restore” operations related to static attributes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T09:59:41+00:00Added an answer on May 18, 2026 at 9:59 am

    The idea is simply to restore the initial known state between tests. Static properties are essentially the same as global variables. Consider

    class TestSubject
    {
        public static $i = 0;
        public function __construct() { self::$i++; }
    }
    

    Now assume you create new instances of TestSubject in your test’s setup method. Because static properties are shared between all instances of a class, TestSubject::i will increase each time you create a new instance. It won’t be reset. It maintains it’s state globally. This is unwanted with Unit-Tests because in order to write reliable tests, you need an isolated, reproducable and known state. Thus, protected members have to be reset between test cases, which you can enable in PHPUnit with the @backupStaticAttributes annotation.

    Example:

    /**
     * @backupStaticAttributes enabled
     */
    class Test extends PHPUnit_Framework_TestCase
    {
        public function testInitialValueOfStaticMemberIsZero()
        {
            $this->assertSame(0, TestSubject::$i);
        }
        /**
         * @depends testInitialValueOfStaticMemberIsZero
         */
        public function testCreatingInstancesIncreasesStaticMember()
        {
            new TestSubject();
            new TestSubject();
            new TestSubject();
            $this->assertSame(3, TestSubject::$i);
        }
        /**
         * @depends testCreatingInstancesIncreasesStaticMember
         */
        public function testStaticMembersAreResetBetweenTests()
        {
            $this->assertSame(0, TestSubject::$i);
        }
    }
    

    If you remove the annotation, the third test will fail.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was reading PC assembly language by Carter and I saw this phrase in
I saw this question asked about C# I would like an answer for PHP.
I saw this code in a PHP book (PHP architect, ZEND PHP 5 Certification
i saw this example : Validate that end date is greater than start date
I saw this question PHP - Get number of pages in a Word document
I saw this C# using statement in a code example: using StringFormat=System.Drawing.StringFormat; What's that
I saw this question and it motivated me to look again (without success) at
I saw this posting which explained how to get BC3 working as the diff
i saw this In MySQL, joins work for INSERT, UPDATE, and DELETE statements. It's
I saw this in a answer by Marc Gravell, and I just don't see

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.