n2963p Posted April 1, 2012 Share Posted April 1, 2012 I've been using PHP procedural programming for some years and do rather well. I'm trying to upgrade my skills to include Object Oriented Programming, but I am having a hard time with one concept. All of the texts seem to limit their examples to it's use on a single page. They don't cover creating an instance on one page and using it on a subsequent page. When I was learning to use MySQL, the texts never mentioned that every time you move from one page to another, you must reconnect to the database. I fought that problem for some time before I found a reference that explained it. Now with OOP instances, do they disappear when you move from one page to another (I believe they do), and what is the common solution to that issue. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/260151-oop-conceptual-question/ Share on other sites More sharing options...
requinix Posted April 1, 2012 Share Posted April 1, 2012 Yes, they disappear too. The exception is sessions. HTTP is stateless: it does not keep track of the state between requests. PHP does not know what happened on the last page. That means every script has to start from scratch: there aren't any variables or classes or database connections from before. The solution is to have your scripts load what they need. Need a class defined? require_once() the file. Need a database connection? Create one. Need a value? Look it up. Quote Link to comment https://forums.phpfreaks.com/topic/260151-oop-conceptual-question/#findComment-1333369 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.