My problem is quite similar to this post: [a link]Creating PHP class instance with a string I want to instance an object from a String however my string came from a object property, I have this:
$type = strval($act->elementtype); $ty="Client";
$societe = new $type;
if I change $societe = new $ty it will work but no for $societe = new $type even when $type is equal to Client which is the name of my class. I recieve:
Fatal error: Class 'Client ' not found in....
It does't seem to be true that $type contains the same as $ty:
Fatal error: Class 'Client ' not found in....
^
You can use var_dump() to trouble-shoot this kind of stuff.
Well.. If someone needs the answer sometime, the think was the type of my variable in my BD elementtype was type CHAR so I try to change it in posgresql and set it into CHAR VARYING and it works!! Hope it help! ^^
Related
I get the following error:
Catchable fatal error: Argument 1 passed to CorenlpAdapter::getOutput() must be an instance of string, string given, called in /Library/WebServer/Documents/website/php-stanford-corenlp-adapter/index.php on line 22 and defined in /Library/WebServer/Documents/website/php-stanford-corenlp-adapter/src/CoreNLP/CorenlpAdapter.php on line 95
index.php 21 and 22 contain:
$text1 = 'I will meet Mary in New York at 10pm';
$coreNLP->getOutput($text1);
corenlpAdapter.php lines 95 and onwards contain:
public function getOutput(string $text){
if(ONLINE_API){
// run the text through the public API
$this->getServerOutputOnline($text);
} else{
// run the text through Java CoreNLP
$this->getServerOutput($text);
}
// cache result
$this->serverMemory[] = $this->serverOutput;
if(empty($this->serverOutput)){
echo '** ERROR: No output from the CoreNLP Server **<br />
- Check if the CoreNLP server is running. Start the CoreNLP server if necessary<br />
- Check if the port you are using (probably port 9000) is not blocked by another program<br />';
die;
}
/**
* create trees
*/
$sentences = $this->serverOutput['sentences'];
foreach($this->serverOutput['sentences'] as $sentence){
$tree = $this->getTreeWithTokens($sentence); // gets one tree
$this->trees[] = $tree; // collect all trees
}
/**
* add OpenIE data
*/
$this->addOpenIE();
// to get the trees just call $coreNLP->trees in the main program
return;
}
Why exactly am I getting this error when text1 is a string?
I am the original author of this class. As you can see, the function getOutput looks like this:
public function getOutput(string $text){
...
}
Change that to:
public function getOutput($text){
...
}
The function tries to enforce that the input is string. The original code should work. However, it seems that in your case, PHP thinks "string" is not actually a string. Maybe the coding environment (the IDE) you are using uses the wrong character set? Or maybe you copy-pasted the code from HTML into the IDE or something like that. Thus whilst it says "string" on the screen, it's not actually a string to PHP.
If you are sure the input is a string, you can safely change the code like above. The class should then work normally.
public function getOutput($text){
.
.
.
}
$columnToChange = $this->getColumnName($questionNo); //Gets EXAMHIST_Q2_JUGDGE
$conn = Propel::getConnection(ExamHistoryPeer::DATABASE_NAME);
//Update the approriate question with user answer in exam history table;
$selectCriteria = new Criteria();
$selectCriteria->add(ExamHistoryPeer::EXAM_HISTORY_ID, $examHist->getExamHistoryId());
$updateCriteria = new Criteria();
//This shows fatal error
$updateCriteria->add(ExamHistoryPeer::$columnToChange, $userAnswer);
//$updateCriteria->add(ExamHistoryPeer::EXAMHIST_Q2_JUGDGE, $userAnswer); //This works
BasePeer::doUpdate($selectCriteria, $updateCriteria, $conn);
Fatal error: Access to undeclared static property: ExamHistoryPeer::$columnToChange
Can any of you guys, please tell me why can not this works, and how to make it work with
ExamHistoryPeer::$columnToChange
PHP is thinking that you want to get static property not constant. It's because of $ sign in ExamHistoryPeer::$columnToChange.
Instead use constant('ExamHistoryPeer::columnToChange') to get values of that constant.
You could maybe do this ?
$oReflection = new ReflectionClass(ExamHistoryPeer);
//Value of the Constant
$mValue = $oReflection->getConstant($columnToChange);
Seems like a simple enough question, so my apologies for asking. As a precursor I'm not necessarily 'new', but rather not so well-versed in PHP.
I have a class, declared as follows:
class User
{
public $id = "";
public function User()
{
$this->$id = isset($_COOKIE['userid']) ? $_COOKIE['userid'] : 0;
}
}
Which seems simple enough, however - upon construction, I get the following set of errors:
Notice: Undefined variable: id in D:\xampp\htdocs\sitecore\include\classes.php on line 13
Fatal error: Cannot access empty property in D:\xampp\htdocs\sitecore\include\classes.php on line 13
Sorry for asking something so simple. The line in question starts with "$this->$id".
Remove the $ symbol at the 'id' place:
$this->id = isset($_COOKIE['userid']) ? $_COOKIE['userid'] : 0;
I've created a object and added it to a array: $array_propriedades[]
$prop = new PropriedadesSoap();
$prop->PROPRIEDADE = 'FORMA_ARMACAO';
$prop->VALOR = $this->input->post('forma_armacao');
$array_propriedades[] = $prop;
And another object, that will be sent to the service like this:
Notice I'm sending the $array_propriedades on $x->PROPRIEDADES
$x = new PropriedadesSoap();
$x->ID_CLIENTE = $this->session->userdata('usuario')->ID;
$x->NOME_PRODUTO = $this->input->post('produto');
$x->OS = $this->input->post('os');
$x->PROPRIEDADES = $array_propriedades;
$x->FK_TIPO_PRODUTO = (int)$this->session->userdata('tipo_produto');
$x->SEU_NOME = strtoupper($this->input->post('nome'));
$pedido = new SoapClient(VendaSO, array("exceptions"=>1));
$res = $pedido->SalvarPedido($x);
I have a class PropriedadesSoap() with nothing inside so I can put everything I want, it was working without the FORMA_ARMACAO property but now I get this error:
SOAP-ERROR: Encoding: object has no 'FORMA_ARMACAO' property
I have no idea of what to do. I've read a article that the user used $pedido->__getTypes() and it worked, not for me, unfortunately.
Any help? Thanks in advance
I'm sorry friends, the problem was happening on the service, the programmer forgot to add some parameters and that is why PHP wasn't able to encode the property.
Hope it helps.
First let me say sorry for the amount of code I'm posting below I'm going to try and keep it as short as possible but this is built on top of my MVC (lightweight-mvc)
Ok So my Problem is that for some reason php is throwing a fatal error on code that should not be being used in my current code,
So how this works I have my MVC witch used the first 2 parts of the url to know what its loading, the problem is I'm building a Moulder CMS into my MVC so it's boot strapping twice,
So here is my Problem,
http://{domain}/admin/control/addon/uploader/method/uploadCheck/
I'm using the above now let me explain a little into that the /admin/control are for the main MVC System it auto-loads the Admin controller then fires the controlAction method from the controller much the same as most MVC's,
The next part are URL paramters that build an array the same as GET or POST would
array('addon'=>'uploader', 'method'=>'uploadCheck')
So from that my control action will auto load as is the code below
public function controlAction(){
global $_URL;
if(cleanData::URL("addon")){
$addonName = "addon_".cleanData::URL("addon");
$methodName = (cleanData::URL("method"))? cleanData::URL("method")."Action" : "indexAction";
echo $methodName;
$addon = new $addonName();
$addon->$methodName();
return;
}else{
$this->loadView("CMS/controll");
}
}
cleanData::URL is an abstract method that just returns the value of the key provided though addSlashes()
So as you can see from the code below it will then use the autoloader to load the module(AKA addon)
Just so you can follow the auto loader works in a simpler version of the Zend Frame work autoloader _ so you have class name addon_admin that would be inside file admin.php that is in the folder addon so the autoloader will load addon/admin.php
So As above with my URL and controlAction it's loading addon/uploader.php and as such this is the contents
<?php
class addon_uploader extends Addons{
public function uploadCheckAction(){
echo 0;
}
public function uploaderAction(){
if (!empty($_FILES)) {
$tmpFile = $_FILES['Filedata']["tmp_name"];
$newLock = "../uploads/".end(explode('/', $tmpFile).$_FILES['Filedata']['name']);
move_uploaded_file($tmpFileName, $newLock);
$POSTback = array(
'name' => $_FILES['Filedata']['name'],
'type' => $_FILES['Filedata']['type'],
'tmp_name' => $newLock,
'error' => $_FILES['Filedata']['error'],
'size' => $_FILES['Filedata']['size']
);
echo json_enocde($POSTback);
}
}
}
?>
But as you can see from my URL its using the uploadCheckAction method witch for debugging i have set so it always says false (AKA 0),
But i seem to get this error:
Fatal error: Only variables can be passed by reference in C:\xampp\htdocs\FallenFate\addon\uploader.php on line 11
But line 11 is $newLock = "../uploads/".end(explode('/', $tmpFile).$_FILES['Filedata']['name']); witch should not be being used could any one provide any help into why this would occur and how i could fix it
end() PHP Manual needs an expression of a single variable (more precisely an array), but not a function return value or any other type of expression.
I think that's basically the cause of your error, more specifically with your code:
$newLock = "../uploads/".end(explode('/', $tmpFile).$_FILES['Filedata']['name']);
you're even driving this far beyond any level of treatment PHP can cope with:
you concatenate an array with a string (which results in a string).
you run end() on that string - not on a variable, not even an array.
I have no clue what you try to do with the code, but I can try:
$filename = $_FILES['Filedata']['name'];
$parts = explode('/', $tmpFile);
$last = end($parts);
$newLock = "../uploads/". $last . $filename;
Or probably even only this:
$filename = $_FILES['Filedata']['name'];
$newLock = "../uploads/". $filename;