473,803 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need a pointer on OOP with php

Hello there,

i am getting to need to make my web stuff more OO.
i have a project at work that we are porting to the internet, and i
started learning php to do so.
the project is now mamoth is size, and code is reused and pasted all
over it. I plan to do a good re-write using better, and cleaner code.
So i want to incorporate some classes.

So i have some questions.

i am writing in eclipse and phpedit on linux.
i wrote a simple class ( by example in a book )

it goes a little something like this:

class Customer
{
var $name;

function get_name()
{
return $this-name;

}
function set_name($new_n ame)
{
$this-name = $new_name;
}
}

my parser complains about field declarations not being declared public,
private, or protected .
what is this talking about ?

another question....

if i create a customer object when say, someone logs into the site. Can
i pass that object to each page in session variables ? like from the
login page, can the user move about the site without me coding the
declarations over and over ?

or is there a better way to go about this ?
still a newbie here.

thanks.

Aug 6 '06
12 1873

Jerry Stuckle wrote:
nephish wrote:
Jerry Stuckle wrote:
>nephish wrote:

Ok, well what i have been doing is creating session variables for
everything possible that relates to what one may call an object (not in
the code, but at the site)
like $name = $_SESSION['name'];
$email = $_SESSION['email'];
$phone = yadda, yadda, yadda

so, i suppose this is still the easier way to pull this off.
thanks for all the info, i am trying to learn as much as possible
because i want to redesign everything in the fall. i started learning
php about a year ago, and a whole lot of stuff i did last Fall, i would
do differently this Fall.
So i want to make it as streamlined as possible.

thanks for all your help

shawn

How I typically do it (since I have my data in a database) is to store
the primary key to the entry in my $_SESSION object. Then I fetch
whatever I need from the database when I need it.

I find this to be much cleaner code. It also fetches current
information in the (admittedly unlikely) event the data is changed while
you're passing it around.

P.S. Please don't top post. This newsgroup uses bottom (or inline)
posting as the standard.

--
============== ====
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attg lobal.net
============== ====

by bottom post, you mean write my stuff at the bottom of the text entry
box ?
like this ? Sorry about that. I have kinda wondered which is better.

Yep, or intermingled, like this. Thanks.

Anyway. I like that idea too. just storing the session variable of the
primary key.
in my case (user_id_number ), and just using that to conquer everything
else.

OK, i have another question about this re-write i want to do. Please
understand, i started learning php about 10 months ago by building our
huge website with it. couple of hundered scripts now.

there is a lot i find on the web about MVC. But also found that it
seems to be best for simple CRUD. What we have here is a lot more
complex. We are pulling machine data, processing it, displaying graphs
of machine effeciency, history of machine performance, etc.. Once
things get complex like that, not like a blog site or something, does
an MVC still make sense ?

thanks.

sk

Probably, but I don't use packages. I typically define my own class
hierarchy. With a little practice and some templates I created, it
doesn't take me long.

One set of classes to interface to the database, then one on top of that
for the business logic.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
now, i had thought of that, because what we are doing is as far from
Drupal as one can imagine. I just thought it might be easier to try to
customize something else. I kinda don't get along with PEAR for db
stuff, but i like it for mail. i suppose i can write my own templates.
At least i would know how it works.

thanks

Aug 9 '06 #11
nephish wrote:
Jerry Stuckle wrote:
>>nephish wrote:
>>>Jerry Stuckle wrote:
nephish wrote:
>Ok, well what i have been doing is creating session variables for
>everythi ng possible that relates to what one may call an object (not in
>the code, but at the site)
>like $name = $_SESSION['name'];
>$email = $_SESSION['email'];
>$phone = yadda, yadda, yadda
>
>so, i suppose this is still the easier way to pull this off.
>thanks for all the info, i am trying to learn as much as possible
>because i want to redesign everything in the fall. i started learning
>php about a year ago, and a whole lot of stuff i did last Fall, i would
>do differently this Fall.
>So i want to make it as streamlined as possible.
>
>thanks for all your help
>
>shawn
>
>

How I typically do it (since I have my data in a database) is to store
the primary key to the entry in my $_SESSION object. Then I fetch
whatever I need from the database when I need it.

I find this to be much cleaner code. It also fetches current
informati on in the (admittedly unlikely) event the data is changed while
you're passing it around.

P.S. Please don't top post. This newsgroup uses bottom (or inline)
posting as the standard.

--
=========== =======
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@a ttglobal.net
=========== =======
by bottom post, you mean write my stuff at the bottom of the text entry
box ?
like this ? Sorry about that. I have kinda wondered which is better.

Yep, or intermingled, like this. Thanks.
>>>Anyway. I like that idea too. just storing the session variable of the
primary key.
in my case (user_id_number ), and just using that to conquer everything
else.

OK, i have another question about this re-write i want to do. Please
understand , i started learning php about 10 months ago by building our
huge website with it. couple of hundered scripts now.

there is a lot i find on the web about MVC. But also found that it
seems to be best for simple CRUD. What we have here is a lot more
complex. We are pulling machine data, processing it, displaying graphs
of machine effeciency, history of machine performance, etc.. Once
things get complex like that, not like a blog site or something, does
an MVC still make sense ?

thanks.

sk

Probably, but I don't use packages. I typically define my own class
hierarchy. With a little practice and some templates I created, it
doesn't take me long.

One set of classes to interface to the database, then one on top of that
for the business logic.
--
============= =====
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@att global.net
============= =====


now, i had thought of that, because what we are doing is as far from
Drupal as one can imagine. I just thought it might be easier to try to
customize something else. I kinda don't get along with PEAR for db
stuff, but i like it for mail. i suppose i can write my own templates.
At least i would know how it works.

thanks
I don't use PEAR, either. Just the mysqli classes on PHP 5 (before I
used the mysql interface).

I have a generic database class template and a table template I can
easily modify. One of these days I'll write a little code to fetch the
columns in the table and gen the entire class. But I never bothered
because it only takes a few minutes to gen the entire class by hand.
Then I modify it for table-specific stuff and I'm done.

The whole thing goes pretty quickly.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Aug 9 '06 #12

Jerry Stuckle wrote:
nephish wrote:
Jerry Stuckle wrote:
>nephish wrote:

Jerry Stuckle wrote:
nephish wrote:
Ok, well what i have been doing is creating session variables for
everythin g possible that relates to what one may call an object (not in
the code, but at the site)
like $name = $_SESSION['name'];
$email = $_SESSION['email'];
$phone = yadda, yadda, yadda

so, i suppose this is still the easier way to pull this off.
thanks for all the info, i am trying to learn as much as possible
because i want to redesign everything in the fall. i started learning
php about a year ago, and a whole lot of stuff i did last Fall, i would
do differently this Fall.
So i want to make it as streamlined as possible.

thanks for all your help

shawn

How I typically do it (since I have my data in a database) is to store
the primary key to the entry in my $_SESSION object. Then I fetch
whatever I need from the database when I need it.

I find this to be much cleaner code. It also fetches current
informatio n in the (admittedly unlikely) event the data is changed while
you're passing it around.

P.S. Please don't top post. This newsgroup uses bottom (or inline)
posting as the standard.

--
============ ======
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@at tglobal.net
============ ======
by bottom post, you mean write my stuff at the bottom of the text entry
box ?
like this ? Sorry about that. I have kinda wondered which is better.
Yep, or intermingled, like this. Thanks.

Anyway. I like that idea too. just storing the session variable of the
primary key.
in my case (user_id_number ), and just using that to conquer everything
else.

OK, i have another question about this re-write i want to do. Please
understand, i started learning php about 10 months ago by building our
huge website with it. couple of hundered scripts now.

there is a lot i find on the web about MVC. But also found that it
seems to be best for simple CRUD. What we have here is a lot more
complex. We are pulling machine data, processing it, displaying graphs
of machine effeciency, history of machine performance, etc.. Once
things get complex like that, not like a blog site or something, does
an MVC still make sense ?

thanks.

sk
Probably, but I don't use packages. I typically define my own class
hierarchy. With a little practice and some templates I created, it
doesn't take me long.

One set of classes to interface to the database, then one on top of that
for the business logic.
--
============== ====
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attg lobal.net
============== ====

now, i had thought of that, because what we are doing is as far from
Drupal as one can imagine. I just thought it might be easier to try to
customize something else. I kinda don't get along with PEAR for db
stuff, but i like it for mail. i suppose i can write my own templates.
At least i would know how it works.

thanks

I don't use PEAR, either. Just the mysqli classes on PHP 5 (before I
used the mysql interface).

I have a generic database class template and a table template I can
easily modify. One of these days I'll write a little code to fetch the
columns in the table and gen the entire class. But I never bothered
because it only takes a few minutes to gen the entire class by hand.
Then I modify it for table-specific stuff and I'm done.

The whole thing goes pretty quickly.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Thats what i had in mind, i need desperately to clean up how all my
stuff works now,
but i could make a class that defines a customer, or a customers
machine, and populate it on the fly from an sql look-up, and keep it
constant throuout. Thats my main mess now, as i learned new stuff, the
site is less and less consistant.

Thanks for your help and advise.

shawn

Aug 9 '06 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3058
by: lawrence | last post by:
I've been bad about documentation so far but I'm going to try to be better. I've mostly worked alone so I'm the only one, so far, who's suffered from my bad habits. But I'd like other programmers to have an easier time understanding what I do. Therefore this weekend I'm going to spend 3 days just writing comments. Before I do it, I thought I'd ask other programmers what information they find useful. Below is a typical class I've...
3
1948
by: Tommy Lang | last post by:
I am working on this project and I need some help/pointers/comments to get me started, I am stuck. The program will be used to store information in an array while it is running. I need to store objects of my classes Person(superclass), Student(inherit Person), Teacher(inherit Person) in that array. The name will be the unique key. These classes are all working ok. I want to be able to add, remove, find etc. objects. To all of this, I...
6
3364
by: BuddyWork | last post by:
C function syntax is PvcsGetRevisionInfo2( HANDLE hArchive, /*Input */ unsigned char *filename, /*Input*/ unsigned char *revision, /*Input*/ unsigned char **author, /*Output*/ unsigned char **versions, /*Output*/ unsigned char **promoGroups, /*Output*/ unsigned char **lockers, /*Output*/
14
2418
by: key9 | last post by:
Hi All On coding , I think I need some basic help about how to write member function . I've readed the FAQ, but I am still confuse about it when coding(reference / pointer /instance) , so I think I need some "template". Sorry for my coding experience in c++
23
2559
by: vinod.bhavnani | last post by:
Hello all, I need desperate help Here is the problem: My problem today is with multidimensional arrays. Lets say i have an array A this is a 4 dimensional static array.
12
3890
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that looked sensible, but it didn't work right. Here is a simple example of what I'm trying to accomplish: // I have a hardware peripheral that I'm trying to access // that has two ports. Each port has 10 sequential // registers. Create a...
7
2832
by: nass | last post by:
hi all, i am running slackware linux and need to use some function that will will enable me to write and read from a shared mem segment.. i am using open() , to open a file, and then use mmap to get a void* file_memory pointer. then i use fwrite(aStruct,structSize,1,(((FILE*) file_memory) + anOffset)) to try to write to the file but it crashes. could it be that fwrite does not understand the file_memory pointer? what else can i use to...
0
2536
by: Pucca | last post by:
Hi I'm using vs2005. I am getting a bunch of compiler warnings after I made some changes to my code that was compiling clean. I'm also getting memory errors when I run my program and it's pinvoking some C++ code, which was working also fine before. I wonder if these warning are causing the problem. I would appreciate some help or suggestions on how to correct these. Thanks. Warning 37 At least one of the arguments for...
8
2936
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using vs2005, .net 2, C# for Windows application. I use DllImport so I can call up a function written in C++ as unmanaged code and compiled as a dll us vs2005. My application is able to call the function, EncodeAsnUser. And it's returning OK but when I display the decoded data in another part of my application it shows no data has been decoded, all fiedls are either null or blanks. For some reason, I am not able to step through...
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10542
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10309
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10289
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9119
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7600
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5496
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2968
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.