| 6:03 am on Jun 18, 2014 (gmt 0)|
turn on error reporting
i think you will get an undefined index error
where do you define $zaza on this page?
| 9:10 am on Jun 18, 2014 (gmt 0)|
I have no error in reporting just at this place the echo don't work
Here my full code
at line 8 it's working
but at line 537 i try many times and no success
maybe at line 52 i should ad something
[edited by: jatar_k at 4:14 pm (utc) on Jun 20, 2014]
[edit reason] way too much code [/edit]
| 1:08 pm on Jun 18, 2014 (gmt 0)|
In the first example, you write:
echo $zaza ;
In the second example, you write:
echo tab(7) . "$zaza";
Shouldn't it be...
echo tab(7) . $zaza;
Because everything between double-quotes is evaluated.
My mistake - I almost never use double-quotes in PHP, so I forgot this.
| 1:49 pm on Jun 18, 2014 (gmt 0)|
strange that i cannot make it work
| 2:40 pm on Jun 18, 2014 (gmt 0)|
The variable is in the global scope?
echo tab(7) . "[START]$zaza[END]";
Then view the source of the page and search for "[START]" - can you find anything?
Aside... you are better off formatting your PHP source code, rather than trying to pretty print the HTML output.
| 2:20 pm on Jun 19, 2014 (gmt 0)|
the result output this => [START]
it echo only the text but not the variable....
| 9:29 pm on Jun 23, 2014 (gmt 0)|
can't find the way to fix this problem crazy :(
| 10:20 pm on Jun 23, 2014 (gmt 0)|
|echo tab(7) . "[START]$zaza[END]"; |
What's the difference between this and
echo tab(7) . "[START]" . $zaza . "[END]";
That's a serious question from someone who doesn't speak php and reads most issues in this subforum as "Been there. Done that". Square brackets give me the willies. I never know when they mean something and when they're just cigars. Er, brackets.
| 11:50 pm on Jun 23, 2014 (gmt 0)|
Square brackets are just text put inside double quotation marks. $zaza is a variable. When variable is inside double quotes it outputs the same way as your second example.
Your foreach misses "}". I hope it there in the original code.
| 9:40 am on Jun 24, 2014 (gmt 0)|
In fact i just want to simply echo the variable $zaza but it's not working only text can be showed at this place don't understand why
| 12:52 pm on Jun 24, 2014 (gmt 0)|
|omoutop: turn on error reporting |
|maxweels: I have no error in reporting... |
Just to clarify... did you enable full error reporting? For example:
error_reporting(E_ALL | E_STRICT);
This might give you some important clues. eg. If the variable is going out of scope and the variable is "undefined". (If E_NOTICE messages are not being reported then nothing will be output.)
There really is only two things that could be happening, either:
1. The variable is out of scope and is undefined (eg. using a global variable inside a function without first declaring it as global).
2. The variable is being overwritten.
You can check for #1 by enabling full error reporting. You can check for #2 by doing a search on your current code base for where you reference $zaza.
|matrix_jan: Your foreach misses "}". I hope it there in the original code. |
From the enormous code dump (which has since been cut from the thread), the curly brace did seem to be closed. $zaza did look as if it was defined and used in the global scope. However, it was an "enormous" code dump with much code in the global scope so it's difficult to say whether it was error free.
@lucy24: yes, as matrix_jan says, the result of those two statements is the same. In this particular case it just comes down to readability and personal preference. (String concatenation of single-quoted strings is marginally more efficient than double-quoted strings and "variable parsing" - but it's a micro optimisation.)
| 1:06 pm on Jun 24, 2014 (gmt 0)|
ok i enable it and now see error
Notice: Undefined variable: zaza in /jcart.php on line 538
line 538 =>
echo tab(7) . "[START]$zaza[END]"; // Here where i try to put the echo $zaza //
so i need to declare it as global ?
| 2:42 pm on Jun 24, 2014 (gmt 0)|
|so i need to declare it as global ? |
Yes, I think so. Looking back at your previous (unformatted) code dump it would seem that that bit of code was actually part of the display_cart() method inside the class (not part of the global scope as I previously thought). $zaza would seem to be declared in the global scope, so you will need the following at the start of the display_cart() method:
Otherwise you are referring to a local $zaza variable which doesn't exist.
Also... I've just noticed that your tab() function is defined *INSIDE* the display_cart() method! Nested functions are just bad in PHP - they aren't really supported. In PHP, all functions are declared in the global scope. When a function is nested like this, the nested function is only declared when the parent function/method (display_cart) is called. The problem is if display_cart() is ever called a 2nd time. In which case PHP will attempt to redeclare the tab() function and you will get a fatal runtime error, "Cannot redeclare tab()...."
| 2:24 pm on Jun 27, 2014 (gmt 0)|
thanks it work :)