PHP Error Undefined Functions [closed] - eval

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I am getting Error Undefined Function.
Here is the code:
$myvar = "#file_get_contents";
eval($myvar("http://someurlupdatehere.com"));
The error I get is:
<b>Fatal error</b>: Call to undefined function #file_get_contents() ..

#file_get_contents() is not a valid PHP function. You can remove the suppression operator to make this work:
$myvar = "file_get_contents";
If you still need to use the suppression operator, do:
eval('#' . $myvar("http://someurlupdatehere.com"));
or even leave the suppression operator and pass the entire line as a string:
$myvar = "#file_get_contents";
eval("$myvar('http://someurlupdatehere.com');");
Note that the use of the suppression operator and eval is generally a bad idea.

It looks really weird to me what you are trying to do. I tend to say "Don't use eval, don't do that!" ;)
Anyway, here comes the right syntax:
$myvar = "#file_get_contents";
eval("$myvar('http://someurlupdatehere.com');");
Or if you need the return value of file_get_contents() in a variable (what is likely, use this:
$myvar = "#file_get_contents";
eval("\$file = $myvar('http://someurlupdatehere.com');");
echo $file;

<?php
$myvar = "file_get_contents";
eval(#$myvar("http://someurlupdatehere.com"));
?>
Works as well. Suppresses errors.

Related

After I use malloc, program suddenly asks for input [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I'm a newbie programmer
//allocating space for final output
//text_count is given by another function, let's just say i have a value for it
//out is my typedef struct
out *fin[text_count];
for(i=0; i<text_count; i++){
fin[i] = malloc(sizeof(out));
}
//this is a test
fin[1]->appearances = 1;
printf("%d",fin[1]->appearances);
// ..other code
I noticed that after this allocation, program suddenly outputs this:
1_
The underscore is blinking, indicating it needs an input.
What can be my problem here? Is it the allocation? Or the codes down below?
okay sorry, let me clarify this, im using codeblocks . so when i get a blinking cursor it means it needs an input. and after i got this output, an infinite loop of inputs seems to be happening.
You're simply seeing the text terminal's cursor. It may be blinking or it may not, that doesn't mean anything in itself.
You might want to add a linefeed:
printf("%d\n", fi[1]->appearances);
to get the output on a line of its own.
A cursor after your printf does not mean, that it is waiting for input.
You can confirm this, by using strace, if it is waiting at read syscall.
Usage:
strace ./myApplication arg1 arg2...

printf to prevent segmentation fault in c [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
The following is a part of a function.
l->length[l->cl] = atoi(p->wds[p->cw]);
printf("FD %d\n", l->length[l->cl]);
p->cw = p->cw + 1;
l->cl = l->cl + 1;
printf("prevent from seg fault\n");
instr(p);
If I remove the printf("prevent from seg fault\n"); I get segmentation fault, but if I keep it it runs and go to the nest function and so on.
So my question is just in general why does this happen, I know I am not showing enough of my code so you can see why the segmentation happen, but if there is any general explanation for this, I also had this in another place in my program but at the end I could remove it?
Regards Orri
As far as the standard is concerned any changes made to a program that invokes undefined behaviour can have any result - there doesn't have to be a logic behind it. And in fact it is very seldom fruitful to try to reason about how a given implementation behaves when encountering undefined behaviour.
That said if a call to printf (or any other function) changes the behaviour of your program (beyond the obvious change of printing what it's supposed to, of course), one possible explanation is that you have an invalid pointer somewhere that points to a local variable that's out of scope. If that variable previously lived in the stack memory that's now used by printf for its own local variables, that means the memory that the pointer points to will now be overridden with a new value. And that can of course change the behaviour of any code that use the pointer.

Bit wise or of two Unsigned Integer (Program Crashes) [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
Sorry if my problem is not very clear.
I've a structure like this:
typedef struct
{
uint32_t typeSet;
}DataTypeTagInfo;
The following function is for unifying two typeSet:
DataTypeTagInfo* unifyTagInfo(DataTypeTagInfo* tag1, DataTypeTagInfo* tag2){
if(tag1 == NULL) return tag2;
else if(tag2 == NULL) return tag1;
tag1->typeSet |= tag2->typeSet;
return tag1;
}
The program exits while executing the following line:
tag1->typeSet |= tag2->typeSet;
On a sample run I've following value:
tag1->typeSet = 3917954189
tag2->typeSet = 2536589
There is no error message. Just quits. Please help.
The code you show is perfectly sound. Consequently, it's very likely that either tag1 or tag2 is an invalid pointer at the time of the abort. This will have nothing to do with the code you've posted. The pointers could be set invalid in many, many ways.
To figure out what's happening, I'd start with a careful review of the code setting tag1 and tag2 at the call site and then - if the answer does not appear - move on to using valgrind to check for memory overwrite errors.
NB this what makes C(++) so challenging.

error expected primary-expression before 'char' [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
i have a question,
i am trying this
if (strncmp(m_DSServer, "TCP:", 4) != 0 )
return DS_AS_PROCESS_NAME_INCORRECT;
if
if(strchr(char *(m_DSServer[4]),':')== NULL) //here it is giving me primary-expression before 'char
return DS_AS_PROCESS_NAME_INCORRECT;
else
if(strchr(m_DSServer[4],'/')== NULL)
return DS_AS_PROCESS_NAME_INCORRECT;
If you want to start searching from the 5. character, do
strchr(&m_DSServer[4],':')
Firstly, cast syntax that has the type(value) form is a chiefly C++ syntax. It is not supported in C. And your question is tagged [C], not [C++]. In C language you have to use the (type) value syntax when you want to perform a cast.
Secondly, even in C++ the type(value) cast syntax requires the type part to consist of a "compact" type specifier, i.e. even in C++ you can't use char * in this context.
Thirdly, regardless of the syntax you use, it is entirely not clear what you are trying to do by casting m_DSServer[4] value (which is apparently a char) to pointer type. This just does not make any sense.
If you wanted to do a search for a : character starting from the 4th position in string m_DSServer, you should do something like strchr(&m_DSServer[4], ':'). No casts necessary.
if (strchr(char *(m_DSServer[4]),':') == NULL)
^^^^^^^^^^^^^^^^^^^^^
char *(m_DSServer[4]) is nonsense. My guess is that you want to search the string for :, starting from the 4th character. In that case, you want a pointer to the 4th character:
if (strchr(m_DSServer+4,':') == NULL)
^^^^^^^^^^^^

sizeof operator in c [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
please can anybody help me to implement sizeof() operator in c..
i know the usage .. but i was not able to implement it.
You cannot implement sizeof() as a library function, it is a compiler intrinsic. Are you writing a compiler?
You can't implement sizeof in C; it's a basic operator (you can't implement + either).
You could write a macro that has a limited subset of sizeof's behavior, by doing something along the lines of:
#define thisIsAHorribleHackDontDoThis(a) \
((size_t)((intptr_t)(&a + 1) - (intptr_t)&a))
but that only works if a is an lvalue (and it's horrible to behold). sizeof is not so limited, and that's why you should use it instead of reinventing a wheel that isn't actually round.
Below is the implementation of sizeof operator
#define SZOF(x) (size_t)(((x*)(0))+1)

Resources