GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   What is wrong with this php line? (https://gfy.com/showthread.php?t=833939)

Klen 06-10-2008 10:22 AM

What is wrong with this php line?
 
I getting error Undefined variable: cat in and i have no idea why.This is line which makes that problem:
PHP Code:

echo "<td valign='top'><p align='center'><a href='girls/$rec->dirname/$rec->dirname.html'><img title='$cat $rec->name Gallery' src='Models/$rec->dirname/1.jpg' alt='$cat $rec->name Gallery' width='150' height='200' border='1' /><br>$cat $rec->name</a></p></td>"

Any idea what is wrong ?

mikesouth 06-10-2008 10:31 AM

yup you are using a reserved word as a variable cat is a reserved word in UNIX

borked 06-10-2008 10:39 AM

$cat doesn't look to be defined (ie has never been called/assigned before) and you are running php with E_ALL

Also, to give the parser an easier time, add braces around your vars when inside double quotes if you absolutely want to have them inside the double quotes

ie

echo "<td valign='top'><p align='center'><a href='girls/{$rec->dirname}/{$rec->dirname}.html'><img title='{$cat} {$rec->name} Gallery' src='Models/{$rec->dirname}/1.jpg' alt='{$cat} {$rec->name} Gallery' width='150' height='200' border='1' /><br>{$cat} {$rec->name}</a></p></td>";


for parser speed inside/outside quotes, have a look at
http://riyono.com/archives/2004/09/3...p-application/

G-Rotica 06-10-2008 10:50 AM

Yea, your code is all red and hard to read.

Klen 06-10-2008 11:06 AM

Ok here is clean copy pastE:
echo "<td valign='top'><p align='center'><a href='girls/$rec->dirname/$rec->dirname.html'><img title='$cat $rec->name Gallery' src='Models/$rec->dirname/1.jpg' alt='$cat $rec->name Gallery' width='150' height='200' border='1' /><br>$cat $rec->name</a></p></td>";

borked 06-10-2008 11:13 AM

like I said, look in your php.ini for what your error settings are - they are probably E_ALL. Set them lower to remove the 'strict' coding messages showing.

k0nr4d 06-10-2008 11:31 AM

echo "<td valign='top'><p align='center'><a href='girls/".$rec->dirname."/".$rec->dirname.".html'><img title='".$cat." ".$rec->name." Gallery' src='Models/".$rec->dirname."/1.jpg' alt='".$cat." ".$rec->name." Gallery' width='150' height='200' border='1' /><br>".$cat." ".$rec->name."</a></p></td>";

you can set "php_flag display_errors off" in htaccess to solve the warning

tranza 06-10-2008 11:54 AM

Quote:

Originally Posted by G-Rotica (Post 14300433)
Yea, your code is all red and hard to read.

I second that.

Klen 06-10-2008 12:05 PM

php_flag display_errors off in htaccess works.I wonder is that only solution.

borked 06-10-2008 04:32 PM

Quote:

Originally Posted by KlenTelaris (Post 14300765)
php_flag display_errors off in htaccess works.I wonder is that only solution.

no, the other solution is to declare your variables before using them.
So, befre tht echo statement, write:
$cat = '';

and then your error will go away.

strict or not-so-strict. The choice is yours

GrouchyAdmin 06-10-2008 04:38 PM

Quote:

Originally Posted by KlenTelaris (Post 14300765)
php_flag display_errors off in htaccess works.I wonder is that only solution.

Actually, the other solution is to learn what you're doing before you try to do it.

Iron Fist 06-10-2008 04:38 PM

My brain is exploding.

brandonstills 06-10-2008 09:01 PM

Quote:

Originally Posted by borked (Post 14300380)
Also, to give the parser an easier time, add braces around your vars when inside double quotes if you absolutely want to have them inside the double quotes

ie

echo "<td valign='top'><p align='center'><a href='girls/{$rec->dirname}/{$rec->dirname}.html'><img title='{$cat} {$rec->name} Gallery' src='Models/{$rec->dirname}/1.jpg' alt='{$cat} {$rec->name} Gallery' width='150' height='200' border='1' /><br>{$cat} {$rec->name}</a></p></td>";


for parser speed inside/outside quotes, have a look at
http://riyono.com/archives/2004/09/3...p-application/

Who cares about giving the parser an easier time? It exists to serve the programmer. I'm tired of all these people bitching about how PHP double quotes are slow. Using single quotes with the '.' operator maybe be faster but ask yourself this. By how much? Ok, even if it is 10 times faster how long do you think that translates to in actual time. Fractions of a nano second. It would have to be deep in an inner loop that is called 100,000+ times before the user would even notice a _slight_ difference. What's more important, having readable code, or shaving an additional 0.000000000001 seconds off the page loading time?

"Premature optimization is the root of all evil."

Now, I'm not one to say you should never optimize. I used to expand assembly code to half a dozen instructions when I could do it with 1 because the MUL instruction used to be really slow on the early x86 platforms. But only inside some kind of loop where it would mean a noticable difference to the user. There's a time and place for optimization but don't make your code more unreadable needlessly.


All times are GMT -7. The time now is 01:38 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123