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 saw this question asked about C# I would like an answer for PHP.
I saw this in an answer to another question , in reference to shortcomings
I saw this same question for VIM and it has been something that I
I saw this quote on the question: What is a good functional language on
I saw this quote in this question : MS support is poor, except when
I saw this signature on the ListView class: public ListView..::.ListViewItemCollection Items { get; }
I saw this the other day (scroll all the way down to see some
I saw this reply from Jon on Initialize generic object with unknown type :
I saw this keyword for the first time and I was wondering if someone
I saw this tip in another question and was wondering if someone could explain

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.