I have been encountering some strange behaviour with some bits of my yii code.Let me pick out one in particular.
The code
$model = new Socialdemo;
$model = $model->findByAttributes(array('fk_recordid'=>$record_id));
$new = new Socialdemo();
$data = $model->attributes;
$data['fk_recordid'] = $new_recordid;
unset($data['id']); //unset id since we want to insert
$new->setAttributes($data, false);
$new->save();
On my local development machine is works just fine but when I deploy it on the server if brings up an error on the line of code
$data = $model->attributes;
It brings out the php error
Trying to get property of non-object
What am I missing?
Do you have the same Db data on server?
have you checked on NULL value?
$model = $model->findByAttributes(array('fk_recordid'=>$record_id));
Why are you missing the brackets after the new declaration
$model = new Socialdemo();
Also, I assume you are including a file to the Socialdemo class, is the file copied to the correct location and path correct on the server?
Related
I'm running PHP 8 on PHPStorm, and I'm trying to create a test for a function that returns an IP string. I'm using PHPUnit & PHPMock
I have the following code inside my test:
$UserIpAddress = $this->getFunctionMock(__NAMESPACE__, 'ip_request');
$UserIpAddress->expects($this->once())
->method('getRealIpAddr')
->willReturn('127.0.0.1');
My error is
Method name is already configured
Yet when I remove it, I get an error that it's expected to be called.
I have copied and pasted the function name, and it definitely is inside the correct class.
My namespaces are correct, and the actual page that uses the function works fine.
Any ideas?
Thanks
Fixed! After a ton of checking various options, the code that should go in the test file is
$local = new ip_request();
$this->assertEquals('127.0.0.1', $local->getRealIpAddr());
and inside the actual class file
$ip = $_SERVER['REMOTE_ADDR'] ?? '127.0.0.1';
I don't think the ?? '127.0.0.1' should be left in for production though.
I am new to PHP and am facing the below issue. There are two files:
In the first PHP file I am writing the below code to create an object
$oNotas = new gcibjdnf($sFiltro, false,'apcconc.nm_apelido', $bBuscarPorChassi);
In the second file-gcibjdnf.php, I have the below code for the constructor
public function __construct($sFiltro = '', $bPaginar = false, $sOrdem= 'apcconc.nm_apelido, danfe', $bBuscarPorChassi = false) {
...}
However,
when I print $sOrdem from the gcibjdnf.php file, I am getting "apcconc.nm_apelido, danfe" as an output.
According to me it should print "apcconc.nm_apelido". But it is printing the default parameter instead of the value passed.
I am using PHP 5.6 version. Please let me know in case anyone has any idea on this.
I don't know how to explain it but, I'm gonna give it a try.
This problem concerns 2 servers, a local and a hosting server. Both servers are running the same PHP version which is 7.0 [with almost same configurations]. And 2 controller actions. And the problem comes from $app->run($input, $out); from the codes below.
I have in my controller that action:
/**
* #Route("/testJson")
*/
public function testJsonAction() {
$app = new \Symfony\Bundle\FrameworkBundle\Console\Application($this->get("kernel"));
$app->setAutoExit(false);
$opt = array("command" =>
"doctrine:generate:entity",
"--entity" => "GuervylEditorBundle:TestOnline",
"--fields" => "kl:string");
$input = new \Symfony\Component\Console\Input\ArrayInput($opt);
$out = new \Symfony\Component\Console\Output\BufferedOutput();
$app->run($input, $out);
$out->fetch();
return new JsonResponse(\json_encode(["a" => "b", "c" => "d"]));
}
Calling this action from the local and hosting server returns "{\u0022a\u0022:\u0022b\u0022,\u0022c\u0022:\u0022d\u0022}" and with Content-Type
application/json which is great, it's the expected result.
Now, here comes the problem:
That almost same code above, I set it inside another class, I call it from another controller action, which passes through 4 methods from different classes to call the method that has the code above [callCommand]
This is the method that implement the code:
public function callCommand($cmd, $opt, &$mykernel = null) {
if ($mykernel == NULL) {
$mykernel = new myKernel("dev", false, __DIR__ . "/../Resources/template_2.8/app");
}
$app = new \Symfony\Bundle\FrameworkBundle\Console\Application($mykernel);
$app->setAutoExit(false);
$opt = array("command" => $cmd) + $opt;
$input = new \Symfony\Component\Console\Input\ArrayInput($opt);
$out = new \Symfony\Component\Console\Output\BufferedOutput();
$app->run($input, $out);
}
From that other controller action, I also return a json content at the end. I can't show the code because it's too big.
When I call that controller action from my localhost, I get the JSON content and Content-Type: application/json which is fine.
But calling it from the hosting server I get extra texts like:
Entity generation
created ./src/Guervyl/EditorBundle/Entity/TestCase.php
> Generating entity class src/Guervyl/EditorBundle/Entity/TestCase.php: OK!
> Generating repository class src/Guervyl/EditorBundle/Repository/TestCaseRepository.php: OK!
Everything is OK! Now get to work :).
Which is the output texts from the console when calling $app->run($input, $out);. After that I get the HTTP header that I set then the json content. And also the content-type is application/x-httpd-php5.
That error only happens on a specific hosting server. I tested other hosting server the code works like on my local server.
My question is why am I getting the error on that specific hosting? Is there something I can change from the PHP.ini to fix it? Because I really need to host my website on that hosting because it offers me great features that I need but the others don't or they are too expensive.
Well, After I debugged the code I noticed that error happened because I did not set the --no-interaction option. So without that option, Symfony was waiting for input when no fields are specified for an Entity.
I have a really serious problem that I have not seen before.
On a website we are using opensource SQC eshop, PHP Version 5.3.3-7+squeeze15 and there is some kind of problem with variable memory I think.
SQC uses notORM and here the problem starts with fatal error "Call to function on non object notORMResult" .
So I dug deeper and found the constructor of NotORM that looks like this:
function __construct(PDO $connection, NotORM_Structure $structure = null,NotORM_Cache $cache = null) {
$this->connection = $connection;
if($_GET['test']){
var_dump($structure);
}
if (!isset($structure)) {
$structure = new NotORM_Structure_Convention;
}
if($_GET['test']){
var_dump($structure);
}
$this->structure = $structure;
if($_GET['test']){
var_dump($this->structure);
exit("1");
}
$this->cache = $cache;
}
And so the output is NULL because the constructor gets no structure param so we create an object. Second output is the object. Then we set the object to attribute and then the THIRD OUTPUT IS NULL
How is this even possible? The site was running for about year and half and no problems till yesterday. I didn't made yet any updates to php and this thing really freaks me out 'cause it's not a constant problem. It just happens sometimes after 2 hours, sometimes after 2 mins and I have really no idea why is this happening.
And btw ... this is just the start it happens across the whole script. Object attributes are set but when you want to read them they give you NULL. There is also second website running on the same server, same php same configuration without problem.
Thanks for any ideas :)
I got this error after i created my DB "Unable to connect to my database server using the provided settings"
Here is code....
* Database Loader
public function database($params = '', $return = FALSE, $active_record = NULL)
{
// Grab the super object
$CI =& get_instance();
// Do we even need to load the database class?
if (class_exists('CI_DB') AND $return == FALSE AND $active_record == NULL AND isset($CI->db) AND is_object($CI->db))
{
return FALSE;
}
require_once(BASEPATH.'database/DB.php');
if ($return === TRUE)
{
return DB($params, $active_record);
}
// Initialize the db variable. Needed to prevent
// reference errors with some configurations
$CI->db = '';
// Load the DB class
$CI->db =& DB($params, $active_record);
}
This actually doesn't have anything to do with your code. Your application can't connect to the database using the provided database settings: (Host, username, and password).
Ensure that you have a database with the correct name and have a Database user setup with access privileges to that database.
The config file is typically located at application/config/database.php.
I've finally find a solution for I think is the same problem that you're having, it's due to the php version that you have at your server, in my case I have php 5.3.5 in my localhost but in my server I had php 5.2.6 I wasn't go further but the main problem was the avoiding notification when a function doesn´t work properly, specifically in "mysql_driver.php"
line 150.
return #mysql_set_charset($charset, $this->conn_id);
get rid of "#", to see the real problem, I found this, stopping each certain part of my script till I finally found where was the problem.
to solve this you can set "$this->use_set_names" to true, so that you can use the if condition near to the line I've pointed out to you.
If the problem wasn't this, probably is something similar, you can test each part of your script (debugging).