SitePoint Sponsor

User Tag List

Page 1 of 4 1234 LastLast
Results 1 to 25 of 79

Hybrid View

  1. #1
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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..

    some direction for a rigid Java developer?

  2. #2
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know it's been said, but this has always been my savior. Having a programming background, just reading on random functions should help you pick it up quickly.

    And welcome to the php forum

  3. #3
    Non-Member
    Join Date
    Nov 2003
    Location
    here
    Posts
    258
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Even SitePoint's book is worth getting (the beginners and anthology)

    I can't imagine how you could find PHP confusing though being experienced in Java, when I do Java at Uni, coming back to PHP is like coming back to a luxury 5 star hotel.

  4. #4
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    Christopher

  5. #5
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  6. #6
    SitePoint Addict fesh's Avatar
    Join Date
    Jan 2005
    Location
    Jackson, New Jersey
    Posts
    218
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so you're looking to try to understand by more of a technical sense, am I clear?

    if that's the case just got to the www.php.net DOC and look for what you don't understand, such as Variables.

    I hope I helped a little.
    Fesh
    imagine what it's going to be like

  7. #7
    SitePoint Wizard DougBTX's Avatar
    Join Date
    Nov 2001
    Location
    Bath, UK
    Posts
    2,498
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    [QUOTE=dc dalton]Well some of the things that REALLY made me say "HUH?" last year when I tried to read that book were these:

    Quote Originally Posted by dc dalton
    1. Everything can be cast into an Array?
    Yep

    Quote Originally Posted by dc dalton
    2. Global is NOT Global (variables wise - now thats just plain weird)
    Yep (though $GLOBALS is)

    Quote Originally Posted by dc dalton
    3. The fact that any variable can have anything assigned to it
    Yep.

    Looks like you have it sorted! What was your problem again?

    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
    Hello World

  8. #8
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DougBTX
    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..

  9. #9
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  10. #10
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken
    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.

  11. #11
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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?

  12. #12
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why are you learning php at all? Honestly, what are your goals?

    I think that might help people understand the sorts of resources you may need.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  13. #13
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by samsm
    Why are you learning php at all? Honestly, what are your goals?

    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.

  14. #14
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dc dalton
    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?

  15. #15
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  16. #16
    orange pips! orange pips!
    Join Date
    Oct 2001
    Location
    Its all about location
    Posts
    652
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This book is the one I started out with many moons ago. It was a great starting reference and I refer to it today still.

  17. #17
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.
    You got that right! Just two days ago I saw you saying you weren't allowed in this forum!

    1. Everything can be cast into an Array?
    Yeah, even keys can be strings, which seems nuts.

    2. Global is NOT Global (variables wise - now thats just plain weird)
    You being an OO developer (Java), I would imagine you know not to use globals!

    3. The fact that any variable can have anything assigned to it (its that strict declaration form Java thing)
    Yeah, PHP sucks.
    PHP Code:
       <?php
       
    // Assign $a to 4.
       
    $a 4;
       
    // Ah, hell, let's make that 4x.
       
    $a .= 'x';
       
    ?>
    Bam! It's a string now. Figure that one out! Trying to figure out that you don't need types is kind of weird. Mind you, it makes things easier. In C, this would be:
    Code:
       {
       	int a;
       	char as[3];
       	a = 4;
       	sprintf(as, "%dx", a);
       }
    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.

  18. #18
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by someonewhois
    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.

    Code:
    class Customer {
    	private String firstName;
    	private int custId;
    
    
    	public void setFirstName(String firstName) {
    		this.firstName = firstName;
    		}
    
    	public String getFirstName() {
    		return firstName;
    		}
    
    	public void setCustId(int custId) {
    		this.custId = custId;
    		}
    
    	public int getCustId() {	
                    return custId;
    	       }
    
    	public void incrementID() {
    		custId++;
    		}
    };
    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?

  19. #19
    SitePoint Wizard Young Twig's Avatar
    Join Date
    Dec 2003
    Location
    Albany, New York
    Posts
    1,355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In PHP:

    PHP Code:
    class Customer 
    {
        var 
    $firstName;
        var 
    $custId;

            function 
    setFirstName($firstName
            {
                       
    $this->firstName firstName;
            }

            function 
    getFirstName() 
            {
                       return 
    $this->firstName;
            }

            function 
    setCustId($custId
            {
                       
    $this->custId custId;
            }

            function 
    getCustId() 
            {    
                       return 
    $this->custId;
            }

            function 
    incrementID() 
            {
                       
    $this->custId++;
            }

    If I understand correctly (I should know this since I know bits of C#.NET), in Java, you cannot do this as firstName is a private variable:

    Code:
    Customer jane=new Customer();
    jane.setFirstName("Jane");
    jane.setCustId(5);
    System.out.println(jane.firstName); //you have to do System.out.println(jane.getFirstName()), right?
    In PHP (at least in PHP4), you can go right ahead and do:

    PHP Code:
    $jane=new Customer();
    $jane->setFirstName('Jane');
    $jane->setCustId(5);
    echo 
    $jane->firstName
    In fact, there's really no need for set/get functions since the vars are public:

    PHP Code:
    $jane=new Customer();
    $jane->firstName='Jane';
    $jane->custId=5;
    echo 
    $jane->firstName
    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. )

  20. #20
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  21. #21
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, and PHP5 supports private/public.

    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?

  22. #22
    SitePoint Wizard Young Twig's Avatar
    Join Date
    Dec 2003
    Location
    Albany, New York
    Posts
    1,355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by someonewhois
    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. )

  23. #23
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Plano
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    another few things about php...

    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.

  24. #24
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Plano
    Posts
    643
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

  25. #25
    SitePoint Wizard gold trophysilver trophybronze trophy dc dalton's Avatar
    Join Date
    Nov 2004
    Location
    Right behind you, watching, always watching.
    Posts
    5,431
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually Twig not bad not bad, maybe someday Ill teach you a REAL language (not that MS ripoff crap)

    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.


    Quote 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!)

    Quote 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?

    AND HOW THE HELL DO YOU INCREMENT A STRING!

    so this would do what?

    $myString = "hello";
    $myString++

    whats the result of that mess?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •