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. 12 1872
nephish wrote:
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 ?
1. If you're serious about OO, learn what they mean.
2. http://nl3.php.net/manual/en/languag...visibility.php It was
introduced in PHP in version 5, in 4 it will not work. From the manual:
"Note: The PHP 4 method of declaring a variable with the var keyword is no
longer valid for PHP 5 objects. For compatibility a variable declared in php
will be assumed with public visibility, and a E_STRICT warning will be
issued."
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 ?
You can: http://nl3.php.net/manual/en/function.serialize.php http://nl3.php.net/manual/en/language.oop5.autoload.php
You might want to ask yourself wether this is really needed, and why exactly
some simple variables aren't enough.
or is there a better way to go about this ?
Just keep in mind OO isn't neccesarily better, and www.php.net is a great
source where you would have found answers to this questions very quickly. Be
sure to read the user contributed notes.
Grtz,
--
Rik Wasmus
First off, thanks for the links and the info, especially the first
link.
Thats what i needed to know.
The system at work uses php4, the system i use at home has php5.
well, suppose i could upgrade works server, but still, passing
everything around as a stream may be a bit more complicated than i
wanted to, but still may be worth it.
i do appreciate the info. Though, i know more about what i am dealing
with.
shawn
Rik wrote:
nephish wrote:
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 ?
1. If you're serious about OO, learn what they mean.
2. http://nl3.php.net/manual/en/languag...visibility.php It was
introduced in PHP in version 5, in 4 it will not work. From the manual:
"Note: The PHP 4 method of declaring a variable with the var keyword is no
longer valid for PHP 5 objects. For compatibility a variable declared in php
will be assumed with public visibility, and a E_STRICT warning will be
issued."
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 ?
You can: http://nl3.php.net/manual/en/function.serialize.php http://nl3.php.net/manual/en/language.oop5.autoload.php
You might want to ask yourself wether this is really needed, and why exactly
some simple variables aren't enough.
or is there a better way to go about this ?
Just keep in mind OO isn't neccesarily better, and www.php.net is a great
source where you would have found answers to this questions very quickly. Be
sure to read the user contributed notes.
Grtz,
--
Rik Wasmus
"Rik" <lu************ @hotmail.comwro te in message
news:b0******** *************** ***@news1.tudel ft.nl...
nephish wrote:
>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 ?
1. If you're serious about OO, learn what they mean.
2. http://nl3.php.net/manual/en/languag...visibility.php It was
introduced in PHP in version 5, in 4 it will not work. From the manual:
"Note: The PHP 4 method of declaring a variable with the var keyword is no
longer valid for PHP 5 objects. For compatibility a variable declared in
php
will be assumed with public visibility, and a E_STRICT warning will be
issued."
This behaviour has been recently changed so that the use of the "var"
keyword does NOT trigger an E_STRICT warning in PHP 5
I have written software that uses PHP's OO capabilities in PHP 4, and it
runs perfectly well in PHP 5. Samples of my code are available from the
websites which appear in my signature.
--
Tony Marston http://www.tonymarston.net http://www.radicore.org
Tony Marston wrote:
>>my parser complains about field declarations not being declared public, private, or protected . what is this talking about ?
1. If you're serious about OO, learn what they mean. 2. http://nl3.php.net/manual/en/languag...visibility.php It was introduced in PHP in version 5, in 4 it will not work. From the manual: "Note: The PHP 4 method of declaring a variable with the var keyword is no longer valid for PHP 5 objects. For compatibility a variable declared in php will be assumed with public visibility, and a E_STRICT warning will be issued."
This behaviour has been recently changed so that the use of the "var"
keyword does NOT trigger an E_STRICT warning in PHP 5
Any idea which version they changed this?
I have written software that uses PHP's OO capabilities in PHP 4, and
it runs perfectly well in PHP 5. Samples of my code are available
from the websites which appear in my signature.
Yup, my own PHP 5 version works perfectly with my previous PHP 4 code.
Grtz,
--
Rik Wasmus
nephish wrote:
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 ?
Hi nephish,
Theoretically you store objects that should have the same lifetime or
shorter as the session in the session. Object that have a longer
lifetime, or have to be shared by multiple users you better store in in
a database. This is called 'persistency'. For more info on persistency
see http://www-128.ibm.com/developerwork...xw01DynamicPHP http://www.onlamp.com/pub/a/php/2005...erloading.html
The thread "PHP Dynamic Database Code" started by jo******@gmail. com on
Fri, 9 Jun 2006 23:13:21 +0000 (UTC) (from which i have the above urls)
may also be interesting.
Saving objects in the session in practice has often brougt me troubles.
The point is you must have its class loaded before the session is
started. This may be easy if you have only one page and one object
class, but i usually have many of both. In my experience it is more
reliable to copy all the objects member variables (but not the ones that
hold objects) into an asspciative array and store the array in the
session. When you later need the object you copy the values from the
array back into a new object.
Furthermore you could take a look at patterns. An example of a pattern
for user interfacing can be found at: http://www.phppeanuts.org/site/index_php/Pagina/195
Many more patterns are at http://c2.com/cgi-bin/wiki?DesignPatterns
(if you get lost, try: http://c2.com/cgi-bin/wiki?search=controller )
Greetings,
Henk Verhoeven, www.phpPeanuts.org.
Some OO terms and definitions: http://www.phppeanuts.org/site/index...7/What+is.html
(contains interpretations specific to the phpPeanuts framework)
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
Henk Verhoeven wrote:
nephish wrote:
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 ?
Hi nephish,
Theoretically you store objects that should have the same lifetime or
shorter as the session in the session. Object that have a longer
lifetime, or have to be shared by multiple users you better store in in
a database. This is called 'persistency'. For more info on persistency
see http://www-128.ibm.com/developerwork...xw01DynamicPHP http://www.onlamp.com/pub/a/php/2005...erloading.html
The thread "PHP Dynamic Database Code" started by jo******@gmail. com on
Fri, 9 Jun 2006 23:13:21 +0000 (UTC) (from which i have the above urls)
may also be interesting.
Saving objects in the session in practice has often brougt me troubles.
The point is you must have its class loaded before the session is
started. This may be easy if you have only one page and one object
class, but i usually have many of both. In my experience it is more
reliable to copy all the objects member variables (but not the ones that
hold objects) into an asspciative array and store the array in the
session. When you later need the object you copy the values from the
array back into a new object.
Furthermore you could take a look at patterns. An example of a pattern
for user interfacing can be found at: http://www.phppeanuts.org/site/index_php/Pagina/195
Many more patterns are at http://c2.com/cgi-bin/wiki?DesignPatterns
(if you get lost, try: http://c2.com/cgi-bin/wiki?search=controller )
Greetings,
Henk Verhoeven, www.phpPeanuts.org.
Some OO terms and definitions: http://www.phppeanuts.org/site/index...7/What+is.html
(contains interpretations specific to the phpPeanuts framework)
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*******@attgl obal.net
=============== ===
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*******@attgl obal.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.
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
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*******@att global.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
=============== === This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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*/
|
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++
|
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.
| |
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...
|
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...
|
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...
|
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...
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |