I upgraded to php 7 and the superglobal request is empty - php-7

I updated from PHP 5.6 to PHP 7.
every $_REQUEST['some_var'] I do returns an error that it is not set...
is it normal that $_REQUEST is empty ?
Example :
echo $_REQUEST['login_ID']
returns
Notice: Undefined index: login_ID in

Check your php.ini file for request_order. Possible it is not set correctly.
http://php.net/manual/en/ini.core.php#ini.request-order
; This directive determines which super global data (G,P,C,E & S) should
; be registered into the super global array REQUEST. If so, it also determines
; the order in which that data is registered. The values for this directive are
; specified in the same manner as the variables_order directive, EXCEPT one.
; Leaving this value empty will cause PHP to use the value set in the
; variables_order directive. It does not mean it will leave the super globals
; array REQUEST empty.
; Default Value: None
; Development Value: "GP"
; Production Value: "GP"
; http://php.net/request-order
request_order = "GP"

Related

Is pass by reference supported in php 7?

Recently we migrated PHP 5.6 to PHP 7
and now following code throws $this->a =& new test($this->f);
Parse error: syntax error, unexpected 'new' (T_NEW)
any ideas? what are the alternation that I could use for it?
As per the PHP7 incompatible changes: http://php.net/manual/en/migration70.incompatible.php
New objects cannot be assigned by reference
The result of the new statement can no longer be assigned to a
variable by reference: <?php class C {} $c =& new C; ?>
Output of the above example in PHP 5:
Deprecated: Assigning the return value of new by reference is
deprecated in /tmp/test.php on line 3
Output of the above example in PHP 7:
Parse error: syntax error, unexpected 'new' (T_NEW) in /tmp/test.php
on line 3
There is no alternative. You were using deprecated behavior, and now it's no longer valid PHP. Simply don't assign by reference.
To clarify Marc B's answer: just remove the ampersand like this
$this->a = new test($this->f);
You can do this as alternative:
$test = new test($this->f);
$this->a = $test;
now the $test is passed by reference and if you change attributes of $this->a, $test attributes will also change. and conversely.
PHP 7 is "pass by reference" by default. if you don't want to pass an object by it's reference, you should do this:
$a = clone $b;

psql returns 'anonymous' in results array

I'm running the following psql on my node server:
SELECT json_data.key AS id, json_data.value::int AS version
FROM players.settings, json_each_text(players.settings.value) AS json_data
WHERE name = $1 AND json_data.value::int > 0;
The results returned include the string anonymous before each result object:
[ anonymous { id: '1ab56bd6-ef7d-4755-92d5-1b0cf7beb4b7', version: 1 },
anonymous { id: '4ea3d884-d2a6-4074-a094-a45f6003e6d4', version: 1 } ]
What am I missing here? I've never seen this anonymous string before and would like to get rid of it.
To my knowledge, you can't get rid of it, at least not on your side.
See: https://github.com/brianc/node-postgres/issues/1062
It's just a Node.js 6 new feature to report into the console when the object was created using an anonymous class.
You can safely ignore it ;)

Knowledge & Connect PHP API, Found object(Account or Answer) but contains only null fields

I'm facing some strange issues when I try to fetch(Connect PHP API)/searchContent(Knowledge Foundation API) following the tutorials/documentations.
Behaviour and output
Following the documentation, we initialize the API. The function error_get_last() (called after the fetch) states that the core read-only file (we are not allowed to modify it) contains an error:
Array ( [type] => 8 [message] => Undefined index: REDIRECT_URL [file] => /cgi-bin/${interface_name}.cfg/scripts/cp/core/framework/3.2.4/init.php [line] => 246 )
After initialization, we call the fetch function to retrieve an account. If we give a wrong ID, it returns an error:
Invalid ID: No such Account with ID = 32
Otherwise, furnishing a correct ID returns an Account object with all fields populated as NULL:
object(RightNow\Connect\v1_2\Account)#22 (25) {
["ID"]=>
NULL
["LookupName"]=>
NULL
["CreatedTime"]=>
NULL
["UpdatedTime"]=>
NULL
["AccountHierarchy"]=>
NULL
["Attributes"]=>
NULL
["Country"]=>
NULL
["CustomFields"]=>
NULL
["DisplayName"]=>
NULL
["DisplayOrder"]=>
NULL
["EmailNotification"]=>
NULL
["Emails"]=>
NULL
["Login"]=>
NULL
/* [...] */
["StaffGroup"]=>
NULL
}
Attempts, workaround and troubleshooting information
Configuration: The account used using the InitConnectAPI() has the permissions
Initialization: Call to InitConnectAPI() not throwing any exception(added a try - catch block)
Call to the fetch function: As said above, the call to RNCPHP\Account::fetch($act_id) finds the account (invalid_id => error) but doesn't manage to populate the fields
No exception is thrown on the RNCPHP::fetch($correct_id) call
The behaviour is the same when I try to retrieve an answer following a sample example from the Knowledge Foundation API : $token = \RNCK::StartInteraction(...) ; \RNCK::searchContent($token, 'lorem ipsum');
Using PHP's SoapClient, I manage to retrieve populated objects. However, It's not part of the standard and a self-call-local-WebService is not a good practice.
Code reproducing the issue
error_reporting(E_ALL);
require_once(get_cfg_var('doc_root') . '/include/ConnectPHP/Connect_init.phph');
InitConnectAPI();
use RightNow\Connect\v1_2 as RNCPHP;
/* [...] */
try
{
$fetched_acct = RNCPHP\Account::fetch($correct_usr_id);
} catch ( \Exception $e)
{
echo ($e->getMessage());
}
// Dump part
echo ("<pre>");
var_dump($fetched_acct);
echo ("</pre>");
// The core's error on which I have no control
print_r(error_get_last());
Questions:
Have any of you face the same issue ? What is the workaround/fix which would help me solve it ?
According to the RNCPHP\Account::fetch($correct_usr_id) function behaviour, we can surmise that the issue comes from the 'fields populating' step which might be part of the core (on which I have no power). How am I supposed to deal with this (fetch is static and account doesn't seem abstract) ?
I tried to use the debug_backtrace() function in order to have some visibility on what may go wrong but it doesn't output relevant information. Is there any way I can get more debug information ?
Thanks in advance,
Oracle Service Cloud uses lazy loading to populate the object variables from queried data using Connect for PHP APIs. When you output the result of an object, it will appear as each variable is empty, per your example. However, if you access the parameter, then it becomes available. This is only an issue when you try to print your object, like this example. Accessing the data should be immediate.
To print your object, like in your example, you would need to iterate through the object variables and access each one first. You could build a helper class to do that through reflection. But, to illustrate with a single field, do the following:
$acct = RNCPHP\Account::fetch($correctId);
$acct->ID;
print_r($acct); // Will now "show" ID, but none of the other fields have been loaded.
In the real world, you probably just want to operate on the data. So, even though you cannot "see" the data in the object, it's there. In the example below, we're accessing the updated time of the account and then performing an action on the object if it meets a condition.
//Set to disabled if last updated < 90 days ago
$acct = RNCPHP\Account::fetch($correctId);
$chkDate = time() - 7776000;
if($acct->UpdatedTime < $chkDate){
$acct->Attributes->PermanentlyDisabled = true;
$acct->save(RNCPHP\RNObject::SuppressAll);
}
If you were to print_r the object after the if condition, then you would see the UpdatedTime variable data because it was loaded at the condition check.

AJAX called files displaying errors when error_reporting=off

In php.ini, my error display settings are as follows:
error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED
display_errors = Off
which works for any normally called file, however, if a file is called using jQuery/AJAX, I receive errors such as:
Strict Standards: Non-static method XML_Util::replaceEntities() should not be called statically, assuming $this from incompatible context in /usr/lib/php/XML/Util.php on line 664
Strict Standards: Non-static method XML_Util::createTagFromArray() should not be called statically, assuming $this from incompatible context in /home/site/public_html/site/paypal/lib/Serializer/Serializer.php on line 1231
Strict Standards: Non-static method XML_Util::attributesToString() should not be called statically, assuming $this from incompatible context in /usr/lib/php/XML/Util.php on line 652
As can be assumed, this is breaking parts of my website, how can I fix this?
I am running PHP 5.4.10
The files are being called using Jquery functions: $.get or $.post
The code/library you are using is triggering a Strict Standards error/notice/warning.
The related error-reporting constant for it is called E_STRICTDocs which was introduced in PHP 5.0Docs.
Since PHP 5.4 E_STRICT is part of E_ALL, so it has to be removed from it as well if you configure the way you do:
error_reporting = E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT
^^^^^^^^^^^
So if you exclude E_STRICT from your production error settings, these Strict Standards errors should not be logged any longer - which would be probably like you would have had it with your earlier PHP 5.3 version.
Additionally you should contact the vendor of the library and request to make the code E_STRICT compatible. This is good practice and also shows you that some code has a certain quality.
For your development you should equally make your code E_STRICT compatible, fixing any place that is causing a Strict Standards error.
Same applies to E_NOTICE and E_DEPRECATED, you should enable these messages in your development environment and fix all the reported problems. This saves you from getting more and more bugs too easily.
From the php.ini:
;;;;;;;;;;;;;;;;;;;
; Quick Reference ;
;;;;;;;;;;;;;;;;;;;
; The following are all the settings which are different in either the production
; or development versions of the INIs with respect to PHP's default behavior.
; Please see the actual settings later in the document for more details as to why
; we recommend these changes in PHP's behavior.
...
; error_reporting
; Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
; Development Value: E_ALL
; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT
The reason why you see the error messages outputted instead of logged is not clear from the information you provide in your question. This can have multiple reasons,
most straight forward because you have not properly disabled display of errors - or enabled it again in the runtime (that setting can be changed from within PHP code, too).
error display is disabled but there is some error handlerDocs that is displaying them anyway.
So apart from the error level setting, this part of your question requires more trouble-shooting on your end to find out why the error messages are being displayed.
See Also:
How to disable E_STRICT (17 May 2010; by rtacconi)
Error Reporting - PHP The Right Way

Undefined variable SESSION

I am using php $_SESSION like this
$_SESSION['original_referrer_location']
but i keep getting this error
Notice: Undefined variable: _SESSION in /var/www/m/inc/referrer.php on line 3
so I added this to the top of my script
ini_set('session.use_cookies', 'On');
ini_set('session.use_trans_sid', 'Off');
session_set_cookie_params(0, '/');
session_start();
and all is good.
Is there a way to turn on sessions for good because having to add this on top of any script that needs a session is kind of redundant....i went to php.ini but there are many calls that start with session...any ideas on what i need to change ...I am on ubuntu 10.10/php5 in case that matters
There is:
http://www.php.net/manual/en/session.configuration.php#ini.session.auto-start
But i wouldn't recommend using it. For example you would like to store whole object in session, to do it you would need to include file with class declaration first, otherwise unserialized object will be of incomplete class.
Other way is to auto-prepend file that sets some basic configuration and starts session
Yes
session.auto.start
session.auto_start boolean session.auto_start specifies whether the session module starts a session automatically on request startup.
Defaults to 0 (disabled).
When you want to use sessions, remember to call session_start() before the HTML tag
<?php session_start(); ?>
<html>
<body>
...