The Grinding Shed: Php - The Grinding Shed

Jump to content

  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

Php Please Help People?

#31 User is offline   Alexander Icon

  • Group: Admin
  • Posts: 3,097
  • Joined: 13-June 02
  • Gender:Male
  • Location:Your girlfriend's thoughts
  • Your fuckin' daddy

Posted 15 February 2004 - 06:35 PM

Dragonfly, on Feb 15 2004, 07:28 PM, said:

OK, I have a few questions about PHP:

1: What's debugging? When do I need it? And how do I do it or use the debugging script? How do I add it in and will it (and is it supposed to) stay in the final product?

2: If you can use echo either with or without brackets, what's the point in the brackets at all? Is it just leftover from old PHP, or do they still have some purpose?

3: If you can use either print or echo, when is it optimal to use which? What situations do each of them meet?

Thanks for any solutions for these little quizzes.

1. Debugging is just the part of the program you write to catch and display error messages in a friendly way, or show you exactly where the program is failing. It's a personal preference how you do it, where you put it and whether you leave it in or not. Usually I turn it off or on with a hardcoded variable at the top of the page ($debug=1 for example), or if I'm pushed for time I just var_dump() any arrays at critical points then delete the var_dump() when it's not needed.

2. No idea, you'll find there are a lot of different ways to do virtually everything in PHP, some are no more "right" than others. It's open source, so this is what happens.

3. print returns a boolean value (true or false), echo doesn't. So you could test if the print was successful or not. Echo doesn't return anything, so it's fractionally quicker. They are different commands, with different behaviours so I guess that's why they're still there.

Hope this helps.
It's not the houses, it's the spaces between the houses.
akpcep.com - Everything | alexanderking.co - Me
0

#32 User is offline   hollow Icon

  • Group: Members
  • Posts: 1,772
  • Joined: 27-August 01
  • Location:Newcastle upon Tyne (UK)

Posted 15 February 2004 - 07:44 PM

On echo and debugging...

1: Occasionally, in a really complicated script, I have a function which contains only the following:

function debug(message)
{ echo("<br/><pre>".message."</pre>");
}

I find this bloody handy, since when i've finished figuring out what's wrong, I can just comment out the echo. Of course, when the scripts completely done, I go and remove all references to it completely.

2: I tend to use echo with brackets, as I prefer to think of it as a function. Using it with brackets also means that if you ever decide you want to redirect the echo to another function you can change things easily with find/replace.

3: I like echo because it sounds more hardcore... :unsure:
0

#33 User is offline   Green Mamba Icon

  • Group: Members
  • Posts: 84
  • Joined: 10-February 04
  • Location:3rd World
  • Interests:The Symbiosis of Life &amp; Death, Comics &amp; Web Design

Posted 19 February 2004 - 01:07 PM

Ok, I've reached a point where I'm thinking that there's no fucking way I'll ever understand this shit. I feel like a fish in a movie theater whatching a sci-fi movie. It's been almost two weeks now and I can't do fuck-all with php except print/echo. None of the code makes any logical sense whatsoever to me.

See, my problem is not learning the indiviual PHP "commands", but rather how all the pieces fit together in an actual webpage. For example ... When do I use a variable, when do I use an array, when do I use a function, or an object? When do I use an if statement, the while statement or the foreach statement?

Maybe my problem is not failing to understand the code itself, but what it does.
So, where can I find out what exactly PHP does in the background? In other words, if I call a function, what exactly does PHP do with the commands I give it in order for it to output the results it does?

Thanks guys...
0

#34 User is offline   hollow Icon

  • Group: Members
  • Posts: 1,772
  • Joined: 27-August 01
  • Location:Newcastle upon Tyne (UK)

Posted 19 February 2004 - 01:31 PM

You use an array when you want a list of similar things that you can loop through, a function when you want a piece of reusable code and an object when what you're dealing with something that has lots of different properties but also needs to be able to do stuff.

Hm, the point of functions is that you shouldn't need to know why it comes up with the result it does. Can you give an example?

This post has been edited by hollow: 19 February 2004 - 01:44 PM

0

#35 User is offline   Green Mamba Icon

  • Group: Members
  • Posts: 84
  • Joined: 10-February 04
  • Location:3rd World
  • Interests:The Symbiosis of Life &amp; Death, Comics &amp; Web Design

Posted 19 February 2004 - 01:42 PM

I'll see if I can find one example that would answer my question ... although I have a problem with anything more complex than print/echo.

I have this "cause and effect thing" where I have to know how things work in order for me to be able to understand them properly. If I understood the inner workings of PHP then I would better understand how to apply the code.
0

#36 User is offline   hollow Icon

  • Group: Members
  • Posts: 1,772
  • Joined: 27-August 01
  • Location:Newcastle upon Tyne (UK)

Posted 19 February 2004 - 02:29 PM

Is good. PHP is very inconsistant, so probably not a good language to be trying to really understand programming structures with.

This post has been edited by hollow: 19 February 2004 - 02:29 PM

0

#37 User is offline   Alexander Icon

  • Group: Admin
  • Posts: 3,097
  • Joined: 13-June 02
  • Gender:Male
  • Location:Your girlfriend's thoughts
  • Your fuckin' daddy

Posted 19 February 2004 - 02:36 PM

My only advice is to apply it to real life applications. Build a site that has to do certain things, then learn how to solve the problems. Taking the whole language as an abstract is a one way ticket to window licking dementia.

Example: Say you're going to build a CMS, start with a form that puts things in a database, then make a script to pull them out, then order them, then search them, etc. Don't forget php is just a tool to do a job. Without a job it's just ASCII.
It's not the houses, it's the spaces between the houses.
akpcep.com - Everything | alexanderking.co - Me
0

#38 Guest_Unforgiven_*

  • Group: Guests

Posted 19 February 2004 - 03:55 PM

Exactly.

That's why/how I learned.

"Hey, wouldn't it be neat to have it do x? How could I do that..." Do that, and go from there. Also, it's a hell of a lot more fun than just dry reading.
0

#39 User is offline   Green Mamba Icon

  • Group: Members
  • Posts: 84
  • Joined: 10-February 04
  • Location:3rd World
  • Interests:The Symbiosis of Life &amp; Death, Comics &amp; Web Design

Posted 19 February 2004 - 07:40 PM

Thanks, that helps

Come to think of it that's exactly how I learned HTML. The only advantage I had there was that I could "view source" on other websites to see how they did certain things. With PHP I can't do that.

Now all I have to figure out is what I can do to start off with. Maybe build a searchable & sortable database for all my comics with a form interface where I can enter new comics to the database whenever I like.
0

#40 User is offline   hollow Icon

  • Group: Members
  • Posts: 1,772
  • Joined: 27-August 01
  • Location:Newcastle upon Tyne (UK)

Posted 20 February 2004 - 08:28 PM

Yeah, a library of some kind is always a good start. Links, comics, news, that kind of thing.
0

#41 User is offline   hollow Icon

  • Group: Members
  • Posts: 1,772
  • Joined: 27-August 01
  • Location:Newcastle upon Tyne (UK)

Posted 08 April 2004 - 02:52 PM

As it stands, not too clever, but within reusable functions and objects which allow you to pass formatting into them, very useful indeed I think:

$format="<li>[id]:[title]</li>";
$query="SELECT title,id FROM sometable";
$result=mysql_query($query);
while($row=mysql_fetch_object($result))
{ echo(preg_replace("/\[(\w+)\]/e", "\$row->\\1",$format));
}
0

  • (3 Pages)
  • +
  • 1
  • 2
  • 3
  • You cannot start a new topic
  • You cannot reply to this topic

2 User(s) are reading this topic
0 members, 2 guests, 0 anonymous users