codeigniter array session issue after move site one server(godaddy) to another server(bluehost) - session

There is issue in session. This is my array.
print_r($this->session->userdata("user_data"));
Array
(
[useremail] => myid#gmail.com
[user_id] => 1
[is_login] => 1
)
I want to get the useremail . so I am writing this code.
print_r($this->session->userdata("user_data")['useremail']);
It gives the error . Parse error: syntax error, unexpected '['
If I am writing the code like this :
$dataval = $this->session->userdata("user_data");
print_r($dataval['useremail']);
Then it it working fine .
Please help me what is issue ?

It is because you (probably) moved from newer php version (5.4+) to older version (5.2).
Accessing array items directly by calling function name is only available on php 5.4 and newer: array dereferencing.
Only solution is to use temporary variable (like your $dataval). Or you can switch to newere php version, if the bluehost allows it.

Related

How do nested variables within the .env file work in CodeIgniter 4

Under the "Nesting Variables" section in Codeigniter4 site:
"To save on typing, you can reuse variables that you’ve already specified in the file by wrapping the variable name within ${...}"
link to CI nesting Variables section
example in the documentation:
BASE_DIR="/var/webroot/project-root"
CACHE_DIR="${BASE_DIR}/cache"
TMP_DIR="${BASE_DIR}/tmp"
I was trying to use the following
app.baseURL = 'http://localhost:8080/'
google.redirect = ${app.baseURL}Google
However, it's assigning it as a literal when print_r($_ENV)
[google.redirect] => ${app.baseURL}Google
I've tried using non-namespaced keys including BASE_DIR (per the example) and it keeps printing as a literal.
What's strange - When I use the following:
CI_ENVIRONMENT = development
google.redirect = ${CI_ENVIRONMENT}Google
The result when print_r is:
[CI_ENVIRONMENT] => development
[google.redirect] => developmentGoogle
My question is - What am I doing incorrectly and/or how should these be set/used correctly?
According to the documentation, I should be able to use any key within the .env file that was already assigned using
${somekeyinthisfile}
After a bit of looking, there is a more recent file up at
https://github.com/codeigniter4/CodeIgniter4/blob/develop/system/Config/DotEnv.php
with all the "other" changes...
This was a Bug Fix. So get that file and you will be good to go.
I am pretty sure that the intention wasn't to allow app.xxx settings to be used as variables as the documentation clearly shows, by not
showing them being used. ( yes its 6am now ...)
BUT it is your code to do with as you please...So if you want to use app.xxx as variables...
The Only Thing missing is the DOT (.) in the regex
If you look on Line 272 - system/Config/DotEnv.php inside method resolveNestedVariables() and add a . (dot) into the regex, that will make all your app.things work.
$value = preg_replace_callback(
'/\${([a-zA-Z0-9_.]+)}/',
function ($matchedPatterns) use ($loader) {
I have added a dot (.) at the end of the [a-zA-Z0-9_
So
'/\${([a-zA-Z0-9_]+)}/',
becomes
'/\${([a-zA-Z0-9_.]+)}/',

How to get Artisan::call('command:name') output in a variable?

Is it possible to get $output as follows:
$output = Artisan::call('command:name');
I have tried many solutions in different posts but it didn't work on my Laravel 5.2.
You can call the output method on Artisan
Artisan::call('command:name');
$output = Artisan::output();
Make sure you are using one of the available output methods like $this->line('output'); in the actual Artisan command. More info in the docs.
There are several ways to accomplish this, but as your are using such old version of Laravel maybe the best for your case is one that will not require a rewrite when you finally migrate to a newer version. Have you tried perhaps the vanilla PHP methods system, shell_exec and passthru?
system will return just the last line of the command on succes and FALSE on failure
shell_exec will return the entire output but without a way to fetch the output status code
passthru will not return any output instead it will output all on stdout. Although it can be put into a variable using output cache methods (i.e. ob_start and ob_get_contents)
In any case you should call those methods using as argument the CLI version of the command you wish to run:
$output = shell_exec("php artisan command:here");
P.S. If you by any chance have a user input that you want to pass as parameter to a artisan command, make sure you escape it with escapeshellcmd first.

Different behavior in Laravel Homestead & Laravel Forge

I had a simple mistake in my PHP Code:
$string += 'something' . $Car->id . ',';
Which resulted in different behavior in Homestead and Forge:
Homestead Result of $string:
0
Forge Result:
Error: A non-numeric value encountered
Does Anybody know why? And how can I change the Homestead behavior to the same like the forge one? It's absolutely better..
Update
I'm sorry I wasn't totally clear in my question. The question wasn't about the mistake itself += instead of .=, I was aware of that.
The question is why in one environment the error appears and in the other one not.
Both environments are configured the same way (php.ini):
error_reporting = E_ALL
display_errors = On
And it was not just a notice, it's an error.
Your issue is because of the += operator. That is used to add numbers together, whereas you're trying to concatenate strings.
You should be using .=
$string .= 'something' . $Car->id . ',';
or alternatively:
$string = $string . 'something' . $Car->id . ',';
The reason you're seeing that message in forge is because it seems to have PHP warnings turned on.
The PHP Version of Laravel Homestead was 7.0.8 and the PHP Version of Laravel Forge 7.1.0-3.
I updated Laravel Homestead to the newest which uses PHP 7.1.0-2, and now Homestead shows up the right error:
Error: A non-numeric value encountered
I'm not shure if it's just the PHP Version or if it's an other change in Homestead with the new version. Thats just what I've found out.
+= adds a number (right value) to a variable's value (left value) and stores it in the variable.
Since your code of
$string += 'something' . $Car->id . ',';
has $string as the left value and contains non-numeric characters, hence the error. You probably meant .= which concatenates a string (right value) to the value of a variable (left value) and stores it in the variable.

puppet ruby wrong number of arguments (1 for 0)

First off, I know there are a lot of questions regarding this error and I have checked them all, mine is not solved using any of their solutions however.
I am working for the first time with Puppet / Ruby and am having the following issue.
I created this function:
module Puppet::Parser::Functions
newfunction(:phpversion, :type => :rvalue) do
%x["/usr/bin/php -r 'echo PHP_MAJOR_VERSION . \".\" . PHP_MINOR_VERSION;'"]
end
end
And when I call it in my manifest file using:
$phpversion = phpversion()
It throws, when I execute the agent, the error "Error: Could not retrieve catalog from remote server: Error 400 on SERVER: wrong number of arguments (1 for 0) at /etc/puppetlabs/puppet/modules/x/manifests/somefile.pp:123 on node foo.example.bar"
I tried adding |args| after the do statement and removing :type but it keeps throwing the same error. when I use $phpversion = phpversion it just thinks its a text string instead of a function (which I expected, but tried anyway).
Any help would be greatly appreciated.
If you're trying to get the version of php, it'd probably be easier to do it as a fact:
Facter.add(:phpversion) do
setcode do
if Facter::Util::Resolution.which('php')
Facter::Util::Resolution.exec('/usr/bin/php -r 'echo PHP_MAJOR_VERSION . \".\" . PHP_MINOR_VERSION;'"').lines.first.split(/"/)[1].strip
end
end
end
Put this a directory lib/facter/ in your module, then reference it in your manifest as $::phpversion

perl package statement and perl module locations

I am writing my first real Perl modules using Moo. But I am getting confused about package locations and package statements and "use".
I have a simple program in c:/temp:
use Roadmap::a;
print a->new->aa->[0] . "\n";
I have a simple module C:/bin/perl/perl/site/lib/Roadmap/a.pm, #INC has:
#INC:
C:/bin/perl/perl/site/lib
C:/bin/perl/perl/vendor/lib
C:/bin/perl/perl/lib
.
If a.pm is this:
package Roadmap::a;
use Moo;
use Types::Standard qw(ArrayRef);
has aa => (is => 'rw', isa => ArrayRef, default => sub{ [3] });
1;
It returns an error:
Can't locate object method "new" via package "a"
(perhaps you forgot to load "a"?) at e.pl line 2.
But if a.pm is this:
package a;
use Moo;
use Types::Standard qw(ArrayRef);
has aa => (is => 'rw', isa => ArrayRef, default => sub{ [3] });
1;
It succeeds and returns the answer '3'. What am I doing wrong? Shouldn't all modules have names of Somedir::Module ?? Thanks!
Update: this is module is simple enough that all I did was create the directory site/lib/Roadmap and place the a.pm file within it. Should I have instead tried to do some kind of perl module install on this simple module? For this simple example, it didn't seem like I needed to.
Update: if I replace "a->new()" with "Roadmap::a->new()" then my original example works. But I was hoping that with a package Somedir::Module, after doing the "use Somedir::Module" in my script, I could then just do Module->new() instead of Somedir::Module->new().
Update: continuing the conversation with myself, if I change the script to this format, it all works the way I want it to. (Of course I would never use a lowercase module name in practice, this is just for testing.)
use aliased 'Roadmap::a';
print a->new->aa->[0] . "\n";
So I guess I have now answered my own question.
"use aliased" solves the problem nicely.

Resources