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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:39:26+00:00 2026-06-03T06:39:26+00:00

I am using PHP 5.3.8 with CakePHP 2.1.1. This is my view (the layout

  • 0

I am using PHP 5.3.8 with CakePHP 2.1.1.

This is my view (the layout is empty, actually it only outputs the view itself)

<?php   
// $present is not a view variable
$present = 'Hello World!';

class ApplicationsPDF
{   
    public function CreateApplicationTable()
    {
        global $present;
        exit(var_dump($present));
    }
}


$pdf = new ApplicationsPDF();
$pdf->CreateApplicationTable();
?>

The output is null instead of “Hello World!”.

If I copy and paste this code into a single file (which I directly run from the browser), it perfectly works!

So it must be a CakePHP bug. Does anyone know it?

  • 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-03T06:39:27+00:00Added an answer on June 3, 2026 at 6:39 am

    It’s not a PHP nor a CakePHP bug!

    It’s because CakePHP includes the view in its view class so the declared variables aren’t really in the global scope and global has no effect.

    From ADmad (source):

    When you run the file by itself your assignment $testVar = ‘Hello
    World!’ is in global context hence things work like you expected them
    to. But when it is used as a view file, the file is included within a
    View class function hence its no longer in global context and $testVar
    is no longer a global var, hence your expectation is incorrect. Using
    global variables in an OOP framework is a bad idea anyway.

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

Sidebar

Related Questions

I am using Cakephp but this is a MVC/php doubt letting the view display
I'm using a simple registration form for CakePHP. This is my edit view: <h2>Add
I'm using the cakephp url HTML helper like following: <?php echo $this->Html->url(array('controller' => 'communities',
Using PHP to try and tackle this problem, but open to other solutions (Python,
Using PHP ... This is for my personal use so I'm thinking maybe 3-4
I'm using cakephp and I want the login view for the controller 'users' to
Using CakePHP 1.3, I have the following layout: /srv/www/_cakephp13/ /app/ /cake/ /plugins/ /vendors/ etc...
I am using cakePHP 1.26. In the PostsController, I have this: $this->paginate=array('conditions'=>array('Reply.post_id'=>$id),'limit' => 1);
I'm using CakePHP 2.0. I have 2 models/controllers (Category/Coupon): // File: Model/Coupon.php // Table
I am using jQuery-1.4.2 with CakePHP and a few days ago I had this

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.