I am creating a function that converts a users initials (STRING) to their userid (INT)
problem is when I call the function I get a call to undefined func error because the below declared function is no where to be found in the Source!
// connect to database -- this works, I checked it
function convertRadInitToRadID($radInits){
$sqlGetRadID="SELECT id FROM sched_roster WHERE radInitials == '".$radInits."'";
$resultGetRadID=mysql_query($sqlGetRadID);
$radID=mysql_result($resultGetRadID,0);
return $radID;
}
...I then create and array ($radNotOnVacay_and_NonMRNotonVacayWeekBeforeAndAfter) of user initials, it works with no errors I tested it independently
$randKey=rand(0,(count($radNotOnVacay_and_NonMRNotonVacayWeekBeforeAndAfter)-1));
$randRad=$radNotOnVacay_and_NonMRNotonVacayWeekBeforeAndAfter[$randKey];
$randAssignedRadID=convertRadInitToRadID($randRad); // call to undefined function error here
when I view source the function definition code (where I define the function) is nowhere to be seen in the source. Very strange. I tried placing it around different areas of the script, same error. The function definition is declared appropriately and is wrapped in .
Very strange. The function just doesn't appear. Quotations, syntax, semi-colons, etc are all spot on.
No syntax errors. Advice?
I Strongly agree with Answer #1.
In addition a usual problems occur in php if you are defining function after calling it. i.e. your calling code is before function defination then it will not run and will give an error of undefined function.
You can create a class then define this function in that class and on the time of calling you can call that function with help of $this->function(args)
I think this will resolve your problem in mean while i am trying to run your code on my machine, lets see what happen
May be your function is a method of some class. So, if it is, you should use it in another way:
MyClass::convertRadInitToRadID($radInits) // if static method
or like this
$class = new MyClass();
$class ->convertRadInitToRadID($radInits)
Trying to make sense of your question... Are you trying to call the function using JavaScript? If so, remember that JavaScript is run on the browser, and PHP is run on the server (and this is why when you "view source" you don't see the function anywhere). To send data back from JavaScript to PHP you should use AJAX.
I found the answer: I was using Jquery UI tabs.... there must be a conflict with tabs. When I run the code without tabs there is no issue.
Thanks for the '==' fix.. appreciate it. my bad
thanks for reminding me about the 80 char varname code limit
Related
I am trying to implement a catch-all exception handler in PHP such that it will set the status code of the response to the status contained in the exception (if present), but for some reason when I pass what is definitely an integer (because I am logging gettype()) into a function, it is somehow turning into a string on the way to that function because if I log its type immediately in the function it is now a string!
Clearly I don't know enough about PHP because this is confounding the heck out of me. Why on earth would this ever happen and how do I stop it from happening?
function qpGlobalExceptionHandler($e) {
$code = intval($e->getCode());
error_log("Global exception (".$code." ".gettype($code)."): ".$e->getMessage());
$this->sendReply($code, $e->getMessage(), false);
}
At this point in the error log I see:
Global exception (404 integer): CouchDB Error: not_found (deleted) …
But inside sendReply, which looks like this:
public function sendReply($responseCode,$responseText=false,$allowCaching=true) {
error_log("In sendReply. gettype(responseCode): ".gettype($responseCode));
// ...
}
In the error log I get:
In sendReply. gettype(responseCode): string
Now I know PHP can be weird, but what the heck?
Update: So I realized one problem, and that was that I was referencing $this from the global exception handler, which is not a member of any class. Strangely the call somehow still ended up making its way to the actual member function I wanted to call, but I'm guessing there must be some strange fallback logic PHP was doing to find the "best match" for the function call and in that logic the parameters ended up getting converted to strings somehow.
Anyhow I have ended up just taking a different approach and it's no longer a problem. I still have no idea what was going on though, so if there are any PHP pros out there who can enlighten me I'd still be happy to learn.
Yeah I know this is probably not the best way to perform this. However I have a script which I would like to call multiple times with parameters and hand over two variables. The code I have so far looks like this:
$testfeld = array('User1'=>'400028',
'User2'=>'400027'
);
foreach($testfeld as $key=>$value) {
$_GET['cmd'] = 'modify';
include("testmodify.php");
}
If I run this code, I get an error message:
Fatal error: Cannot redeclare show() (previously declared in testmodify.php:14) in testmodify.php on line 39
If I perform this, it only modifys me the first entry of the array and then throws me the error message above.
Sadly, I have only read access to testmodify.php.... So is there a way to perform this include with all the content of the array?
Put your code in the function, include it once and call as much as you want.
You are receiving this error because the file testmodify.php contains the definition for "show". A second inclusion of the file caused by your loop attempts to define the object show again, which cannot be done.
Here is another SO question about someone trying to redefine a function.
Php and redifining
Edit: the other answer by MilanG is how you could go about fixing it.
You can do something like (in your testmodify.php script):
if (!function_exists("show")) {
function show($parameters) {
/* do your stuff here */
}
}
A better thing to do, in this case, would be to perform include_once() in your testmodify.php script, making it point to a script file where you define your show() function. My approach should also work for you.
Hope that helps :)
Why is this line of code:
$this->plugins_dir[0] = SMARTY_DIR . 'plugins';
causing this error?
ERRNO: 8
TEXT: Indirect modification of overloaded property Page::$plugins_dir has no effect
By the way, the line of code is inside the constructor of a class named 'Page'.
I am working with PHP and PostgreSQL, but am not too experienced. I am stuck
with this problem for few hours now, can't find the reason.
What PHP is trying to tell you is that the property ->plugins_dir doesn't really exist, but a magic __get() function has been written that will return a value if you read from it. Assigning a variable directly to it might also work (if there is a corresponding __set()) but you cannot modify it, since it is actually a function return value. You are effectively trying to say $this->__get('plugins_dir')[0] = 'foo', which doesn't mean anything.
However, looking at the relevant Smarty documentation, we can see what the correct solution is:
Note: As of Smarty 3.1 the attribute $plugins_dir is no longer accessible directly. Use getPluginsDir(), setPluginsDir() and addPluginsDir() instead.
So your code should actually use the pattern of one of the examples on the doc page for addPluginsDir(), such as:
$this->setPluginsDir( SMARTY_DIR . 'plugins' )
->addPluginsDir( '/some/other/source/of/plugins' );
I think this is the right way
$this->plugins_dir = SMARTY_DIR . 'plugins';
I'm working with 0.9.5 and I'm doing some phpunit tests.
When I execute my second test, that invokes again the webservice, I'm getting this error:
Undefined index: _transient
/var/www/dev_folder/nusoap/nusoap.php:227
/var/www/dev_folder/nusoap/nusoap.php:7293
when
$client = new nusoap_client($this->_config->URL_Path . $webserviceWSDL, true);
is executed by a second time.
I checked nusoap.php and seems something related with globals or something static or singleton... but I don't know what can I do to solve the problem...
$GLOBALS['_transient']['static']['nusoap_base']['globalDebugLevel'] = 9;
Need nusoap client to be unloaded or something like this? Why this global variable is failing?
Thank you.
I had the same problem. The comments seemed to indicate that the global variable was an attempt to emulate a static class variable, so I simply updated the code to actually use a static class variable in the nusoap_base class. That seemed to do the trick.
You can checkout the code here.
I'm trying to make a simple JQuery JSON call with some HTML, JS, and PHP, but it seems like there's a bug in my createBuilding() function. One of the first thing the function does is create an alert box and not even that shows up. When I check the Javascript console I get Uncaught Reference Error. I made a JS Fiddle to see if anyone can help!
http://jsfiddle.net/LpFTj/1/
Thank you for all your help!
You seem to confining your function to the scope of DOM Ready event .. So you cannot access outside of .. Also a type in this element buildingType
var buildingFinalType = document.getElementById('builtingType').value;
Move createBuilding outside $(document).ready. Since it is defined in a function it is not available outside the scope of that function i.e. not globally available.