Skip to content
Advertisement

Tag: global

How to json_encode $GLOBALS?

I’m trying to debug a PHP application, and as a section of the debug process, I passed print_r($GLOBALS) through the AJAX request to my browser. However, I’d prefer to see it in native JSON form because it comes out better in the browser. I’m trying to use the following snippet of code: but I’ve found it returns bool(false). The JSON

Alternative for define array php

I’m looking for an alternative for define(‘name’, array) as using an array in define gives me this error: Constants may only evaluate to scalar values in … The array I’m mentioning contains strings only. Answer From php.net… The value of the constant; only scalar and null values are allowed. Scalar values are integer, float, string or boolean values. It is

Global variable is not working as expected in PHP

I’m trying to make my own simple framework in PHP. It’s going OK but I’m running into a problem. I redirect everything back to my index.php, and from there I start loading classes and functions. I split up the url into segments, which works fine, until I want to use the segments in a class. I have a main controller

Codeigniter variables from constructor are undefined

I’m using CI’s Auth Tank library to query records for certain users. The variable $user_id = tank_auth->get_user_id(); grabs the user id from the session. I want to pull records where user_id = $user_id. From what I understood, constructors can load variables each time a class is initiated. Sort of like global variables. So I figured I’ll set my $user_id in

Advertisement