The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

OK, I HAVE to learn this stuff !

Well I know there will be a few shocked faces over here .. seeing me post here BUT, I have to make a stab at it again.

First off Ill tell you I am HARDCORE Java ... beaten into my brain. BUT it frustrates the heck out of me that PHP gives me problems. I do some, more like hacking, and the code somewhat makes sense to me. Ive built a few EASY sites using it but keep finding myself saying "boy Id like to do that, if I could figure it out" .... anyway, I build BIG TIME Java server-side apps and Id like to start trying to do what I do in Java in PHP where possible... I think it would add more to my "worth"

I TRIED the Core PHP book last year and spent most of the time saying HUH? So Id like to hear from you folks, a book, a website or just hack my way thru..

I would recommend looking at some of the advanced PHP projects and frameworks around, such as WACT, Mojavi, Propel, etc. Most are built by people with both Java and PHP knowledge.

It take a little mind bending to see both the Java and PHP point-of-views. The decision to not have an app server, threads, shared memory, etc. makes your approach to building web apps different. The basics are still the same, but you will have to build some things yourself that you used canned libs for in Java. You will also have to work harder to maintain layer separation in PHP.

If you can (early on) find a way to make your peace with the things that seem to bug Java developers to no end (like naming inconsistency or lack of the Java features mentioned above), you'll be fine. Some Java developers never can though.

Well some of the things that REALLY made me say "HUH?" last year when I tried to read that book were these:

1. Everything can be cast into an Array?
2. Global is NOT Global (variables wise - now thats just plain weird)
3. The fact that any variable can have anything assigned to it (its that strict declaration form Java thing)

The loops, functions etc are all readable to me ... just some of the ways they do things... Even the includes and requires were kind of a HUH?

PHP is a type-less language. This philosophy extends all through the langauge. While in java, you generally have one way to do things right, PHP offers you a lot of parallel functionality. Thus there are many ways to approach the same problem in PHP. This must be very confusing for learners - on the other hand it also gives you a lot of freedom.
I think the best thing you can do, is NOT to try and grasp everything beforehand. Just dive in, and solve the problems along the way. This is what PHP is really good at - hacking stuff together along the way.

I think the best thing you can do, is NOT to try and grasp everything beforehand. Just dive in, and solve the problems along the way. This is what PHP is really good at - hacking stuff together along the way.

well that might be the best way .... I think trying to understand why is whats killing me.

Kinda was expecting a thread from yourself, in the PHP forums after our PMs

If your still learning PHP, APress still has it's free download (A Programmers Guide to PHP4.0) which may help you? The link is on their home page, www.apress.com if your interested

What helped me learn PHP in the beginning was the 10 part article on this very site by Kevin Yank, which is now not available I note, but these articles were a pre-cursor to the book published by Sitepoint by Kevin Yank.

So, between these 2 books, and the on-line manual (which is a life safer btw), these might get you started?

it's probably a good idea to start with php5, since some of the real oddities of php have been corrected. comming from a java background your bound to break your neck on such things as references. do mind though, that most tutorials are targeting php4.

I think that might help people understand the sorts of resources you may need.

WELL, Im not 100% sure myself ... one thing I intend on doing is building some sites (or apps) for myself with the intention of reselling them at some point in time. I have some really amazing apps Ive built in Java but selling them to the (unknowing) public I get the old sour face "java?"

The other thing I am doing this year is building a ton of little sites for myself (or buying them) and then customizing them to what I really want them to do. Ive bought a few and many of them came with premade PHP scripts etc. Ive been able to hack my way thru some of them but again I keep hitting the "Id love to do this, BUT" ... It really irritating because in Java its one two three .. done!

So it depends on the site or app ... If it were just for me Ill do it in Java in a second ... but if there's a chance Ill sell it at some point I think my odds of selling it will be a LOT higher if it were built in PHP.

Ive bookmarked the books you've recommended, thanks and I HAVE heard PHP 5 has cleaned things up a bit ... the book I have here is PHP 4.

Ive bookmarked the books you've recommended, thanks and I HAVE heard PHP 5 has cleaned things up a bit ... the book I have here is PHP 4.

That is my understanding as well. However, the major advantage of PHP (4) is its ubiquity... and PHP 5 is far from that level of penetration. I'd bet that PHP 5 will creep onto the scene, but how fast is an unknown.

Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

Oh, and I'm guessing this is an anit-Java thing, but in PHP you can do this:

PHP Code:

$my_array[] = 'appended value'

hth,
Douglas

UH, yeah that wouldnt even compile .... yesh, its stuff like that just makes me say "what the heck were they thinking", thats assigning a String to an array, not putting it in - assigning it! But again I am SO programmed (no pun intended) in that strictly type Java thing .... I gotta get over this..

Ya know I just thought of something else about this language that makes me twitch .... it looks just like Perl (used to that back in the old days - UCK!)

Think Im going to grab a book this week and start plowing into it again..

Which I imagine is similar to Java. I'm not sure if Java requires you to declare the variables immediately after the opening of a block, though.

No in Java you only need to declare them before using them. As far as globals there are VERY few times we use them, well not like you might think BUT in an object in Java you would declare most of your variables as global TO THAT OBJECT ONLY... but the trick is in java you declare them as private ... only that instance of that object can access them.. an example (and maybe someone could show me in php the same thing) .. it might help here.

Now this is a REAL plain jane basic object but its a real world example of something like you might use with a shopping cart or something like that. Now the 3 variables declared (globally) are private to the instance of the Customer object that is referenced ... there is NO WAY to access them without using the setter and getter method ... so if Im reading it right in PHP the setFirstName method could NOT assign the incoming value to the variable?? Am I right there?

Also (just as a side note) those variables will automatically be set to null the second the instance is created and will only contain data once explicity assigned to them... same same?

Ah, well, that's a lot better than C. C has to have them declared at the opening of a block (beginning of a function, if statement, while, etc.), which is an absolute pain, especially if you've got a relatively long function. You end up with a dozen declarations at the top, then the definitions and uses down below -- it's really hard to follow. I guess that's why people started migrating off of C in favour of things like Java.

And with PHP, since you don't need to declare, you don't need actually have any null variables (or rarely will you). In C, though, it's null until defined.

Oh, and I apologize for my pretending to know anything about Java. As I said, I know bits of C#.NET, but I have no idea how Java writes a line. (I think I saw System.out.println in the Java forum once. )

One thing else about lack of types, you don't need to declare the function as a type. You can return an array, string, int, etc. all from the same function.

Other than that, the only differences between your code and PHP5 would be -> instead of . and $ in front of dollar signs. Oh, and you have to go $this->custid, not just $custid -- though I thought that was the case for Java too?

1. you dont hav to state the size of an array ever
2. php wont freak out if u try to call a variable that hasn't been instantiated yet
ex. if you do $x++ before $x has been declared, it will only give you a subtle warning, and it wont even give you that if you have error reporting turned off.
3. php automatically determines which type avariable needs to be based on what function you are trying to use
ex. $x = 42; if ($x){ // will work because it treats it as a boolean
ex. $string = "425"; $string++; // will work because it treats it as an int

besides that, i dont see any noticable differences that haven't been touched
ex.

Oh, and you have to go $this->custid, not just $custid -- though I thought that was the case for Java too?

In C#.NET (no, they're not the same, but they look the same), you can get away with this.var or just var. I'm not sure how it works in Java, though. (I assume it's the same way. Dave can't make mistakes. )

In C#.NET (no, they're not the same, but they look the same), you can get away with this.var or just var. I'm not sure how it works in Java, though. (I assume it's the same way. Dave can't make mistakes. )

in java you can only do that if its local, otherwise you must use the class identenfier

But you are correct in your statement, because the variable firstName is declared as private you could NOT access by

System.out.println(jane.firstName);

Matter of fact it wouldnt even compile, the compiler would tell you it has private access..

This is just basic encapsulation, locking down your data so that it can only be accesed via you methods..

Now Ill also tell you the this. in my code is NOT required, it is implied .. but I got into the habit of it years ago and never went the "shortcut" .. I could have done:

Code:

public void setFirstName(String firstName) {
firstName = firstName;
}

I know ... confusing looking, thats why I use the this.

Originally Posted by XtrEM3

2. php wont freak out if u try to call a variable that hasn't been instantiated yet

OK so how the hell does it process it if it doesnt yet EXIST (see this type stuff makes me NUTS!)

Originally Posted by XtrEM3

3. php automatically determines which type avariable needs to be based on what function you are trying to use
ex. $x = 42; if ($x){ // will work because it treats it as a boolean
ex. $string = "425"; $string++; // will work because it treats it as an int

OK, theres one of those "HUH?" moments ... actually two!

so your telling me PHP falls back to the "old school" of anything besides a 0 or negative number is true?