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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T11:47:02+00:00 2026-06-07T11:47:02+00:00

I cant figure out what is wrong with the following code: class ArticlesController extends

  • 0

I cant figure out what is wrong with the following code:

class ArticlesController extends AppController{
    var $name = 'Articles';
    // Variable $today is defined here so it can be used
    // in other functions in this same class 
    var $today = date('Y-m-d H:i:s',strtotime('now'));
    var $helpers = array('Video');

    function frontpageArticles(){
        $articles = $this->Article->find(
            'all',
            array(
                'conditions' => array(
                    'Article.published' => 1,
                    'Article.publish_date <=' => $today // USED HERE
                )
            )
       )
    );
    return $articles;
    }

    // ...
}

I am getting the following error message:

Parse error: syntax error, unexpected '(', expecting ',' or ';' in /home/XXXXXXXX/public_html/app/controllers/articles_controller.php on line 10

And this is in LINE 10 var $today = date('Y-m-d H:i:s',strtotime('now'));

Thanks,

  • 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-06-07T11:47:03+00:00Added an answer on June 7, 2026 at 11:47 am

    To elaborate further on what Julien’s answer stated, you can’t use functions in variable assignments in a class declaration, you can of course when you’re defining normal variables.

    A way around this would be to assign your values in the constructor, like so:

    class ArticlesController extends AppController
    {
        public $name = 'Articles';
        // Variable $today is defined here so it can be used
        // in other functions in this same class 
        public $today;
        public $helpers = array('Video');
    
        public function __construct()
        {
            parent::__construct();
    
            $this->today = date('Y-m-d H:i:s'); // You also don't need strtotime('now');
        }
    
        public function frontpageArticles()
        {
            $articles = $this->Article->find(
                'all',
                'conditions' => array(
                    'Article.published' => 1,
                    'Article.publish_date <=' => $this->today // USED HERE
                )
            );
            return $articles;
        }
    
        // ...
    }
    

    Just a side note, var is PHP4 syntax, so if you’re using PHP5 I would highly suggest that you use the access modifiers ie. public/private/protected to define both your fields and methods based on how they will be used.

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

Sidebar

Related Questions

I cant really figure out whats wrong with this. I used to write the
Total newbie question, but I cant figure out what im doing wrong. I want
I can't figure out what's wrong with this snippet of code. I have an
I have code that looks like the following in a class that extends MembershipProvider
I can't figure this out. I have the following code: import java.util.ArrayList; import java.util.List;
It's late and I can't figure out what is wrong with my syntax. I
I can't figure out what I am doing wrong with my query here. SELECT
I can't figure out where I'm going wrong here. Trying to validate an email
I can't figure out what I'm doing wrong in this template. Here's my data:
I can't figure out what exactly is wrong. This is what i get when

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.