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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:21:46+00:00 2026-05-24T21:21:46+00:00

It’s the first time I use OOP with PHP 5.. so this is my

  • 0

It’s the first time I use OOP with PHP 5.. so this is my problem..

I have a file disp.php that contains a class named class disp (model in MVC)

<?php
class disp{
public $n_pages;
public $current_page;
private $cmd2;

/***************SQL command generator*******************/
private function getCmd2($cmd1,$id,$first_entry,$perpage,$tri){
    $cmd2=str_replace('COUNT(*)','*',$cmd1);
    $cmd2=$cmd2.' ORDER BY '.$id.' '.$tri.' LIMIT '.$first_entry.','.$perpage;
    return $cmd2;
}


/********************Items display******************/
function dispItems($cmd1,$id,$perpage,$tri){
  require('global/connection.inc.php');
  try{

     foreach($pdo->query($cmd1)as $r){
       $n_pages=ceil($r[0]/$perpage);
           if (isset ($_GET['pg'])){
          $current_page=intval($_GET['pg']);
               if ($current_page>$n_pages){
                    $current_page=$n_pages;
               }
               if ($current_page<=0){
                   $current_page=1;
               }
           }
           else{
           $current_page=1;
           $_GET['pg']=1;
           }
    }


    $i=1;
    $first_entry=($current_page-1)*$perpage;

    $objet=new disp();
     $cmd2=$objet->getCmd2($cmd1,$id,$first_entry,$perpage,$tri);

    $data=array();
    $i=0;
    foreach($pdo->query($cmd2) as $r){
    $data[$i]=$r;
    $i++;
    }

  return $data;
  }catch(PDOException $e){}
}
}

this is the file news.php (controller in MVC):

require MODELS_DIR.'disp.php';
$objet=new disp();
$news=$objet->dispItems('SELECT COUNT(*) FROM tbl_nouveautes','ID_EVENT',10,'DESC');

$c_page=$objet->$current_page;
$n_pages= $objet->$n_pages;


require VIEWS_DIR.'disp-news.php';

in this code, I created an object (objet) of the type disp… I want to use the variables declared in the function dispItems, ($n_pages and $current_page) in the view (disp-news.php)

so I think that the class variables are the same variables in the function dispItems()… but when trying to access them from the controller …using object. it shows me a error :

See:

Notice: Undefined variable: n_pages in C:\Program Files\EasyPHP-5.3.6.1\www\example\admin\global\news.php on line 14

Fatal error: Cannot access empty property in C:\Program Files\EasyPHP-5.3.6.1\www\example\admin\global\news.php on line 14

Inspite of $n_pages and $current_pages being public in the class disp

thank you in advance

  • 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-24T21:21:47+00:00Added an answer on May 24, 2026 at 9:21 pm
    c_page=$objet->$current_page;
    n_pages= $objet->$n_pages;
    

    should be

    $c_page=$objet->current_page;
    $n_pages= $objet->n_pages;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a reasonable size flat file database of text documents mostly saved in
I'm trying to create an if statement in PHP that prevents a single post

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.