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 6676579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:00:25+00:00 2026-05-26T04:00:25+00:00

I am getting the error Undefined variable: interval in C:\wamp\www\DGC\classes\DateFilter.php Here is my code

  • 0

I am getting the error “Undefined variable: interval in C:\wamp\www\DGC\classes\DateFilter.php”

Here is my code for the DateFilter class:

class DateFilter extends Filter
{
    //@param daysOld: how many days can be passed to be included in filter
    //Ex. If daysOld = 7, everything that is less than a week old is included
    private $interval;

    public function DateFilter($daysOld)
    {
        echo 'days old' . $daysOld .'</ br>';
        $interval = new DateInterval('P'.$daysOld.'D');
    }


    function test()
    {
        echo $interval->format("%d days old </br>");
        //echo 'bla';
    }

}

When I create a new instance of the DateFilter class and call test() it give me the error. I realize it means the variable hasn’t been initialized, but I know that the constructor is being called because I put an echo statement in there and it was output.

I have also tried:
$this::$interval->format(…);
self::$interval->format(…);
but it didn’t work.

I know this is probably an easy fix, sorry for the noob question. Can’t believe this stumped me.

  • 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-26T04:00:25+00:00Added an answer on May 26, 2026 at 4:00 am

    You have to use $this->interval to access the member variable interval in PHP. See PHP: The Basics

    class DateFilter extends Filter
    {
        private $interval;    // this is correct.
    
        public function DateFilter($daysOld)
        {
            $this->interval = new DateInterval('P'.$daysOld.'D');   // fix this
        }
    
        function test()
        {
            echo $this->interval->format("%d days old </br>");     // and fix this
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am getting errors if smarty variable is undefined. Here is the code: <
I have a problem where a method is getting an undefined variable error, even
I am getting JQUERY undefined error. Do you have any idea (code below). <%@
Why am I getting an undefined label error in following code? (I am leaving
I am getting the following error in the following code: Class primeField implements field
I recently setup a new web server and I'm getting undefined variable error. If
I'm getting this error : undefined local variable or method sessions_path' for #<#:0x2db44c8> when
Trying to compile a iPhone/iPad application with SDK3.2 and am getting this error: Undefined
I am getting the following error: Microsoft JScript runtime error: 'Sys' is undefined While
I am getting a Microsoft JScript runtime error: 'Sys' is undefined error on one

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.