473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

PHP5 Object and Class Errors

I've been doing some level of PHP programming for many years now, and
have in the past few months started implementing lots of the core PHP5
features into a new project, when I noticed some interesting issues
with objects and classes.

I'm having some problems with Object Oriented PHP5, namely when a class
isn't defined correctly no errors are produced during object
instantiation. For example if a method which violates a global
namespace is defined inside a class I cannot get PHP to throw an error
when that class is instantiated. PHP will catch simple errors such as
lines not ending in semicolons, but doesn't catch these more 'global'
issues.

Worst of all, in my example where I violate the namespace, the program
fatally dies and does so silently.

If anyone else has experienced this issue, or if anyone knows how to
get these types of errors to report themselves, it would be much
appreciated.

I'm sure this has been covered before and I just couldn't find the
answer to my question on the board.

Again, any help is much appreciated.

Thanks,
Nate

Apr 8 '06 #1
6 1422
n8*****@gmail.com said the following on 09/04/2006 00:44:
I'm having some problems with Object Oriented PHP5, namely when a class
isn't defined correctly no errors are produced during object
instantiation. For example if a method which violates a global
namespace is defined inside a class I cannot get PHP to throw an error
when that class is instantiated. PHP will catch simple errors such as
lines not ending in semicolons, but doesn't catch these more 'global'
issues.


What do you mean "a method which violates a global namespace?" Can you
give an example?
--
Oli
Apr 9 '06 #2
class TestClass
{
public function list(){
echo 'list';
}
}

`list` is a built in PHP method, so by declaring it in an object, it
violates the global namespace. php won't complain about this method
being in the class, until you try to instantiate it as an object. then
it will just fatally fail silently.

Apr 9 '06 #3
Nate said the following on 09/04/2006 02:03:
class TestClass
{
public function list(){
echo 'list';
}
}

`list` is a built in PHP method, so by declaring it in an object, it
violates the global namespace.
list() is actually not a function/method, but a language construct, and
as such, doesn't belong to any namespace.

Use of language constructs as method names is not allowed, however, use
of "global" function names is, replace your "list" example with "count",
for example.
php won't complain about this method
being in the class,


Yes it does, if you have errors set appropriately. With E_ALL, I get
the following message:

Parse error: parse error, unexpected T_LIST, expecting T_STRING ...
--
Oli
Apr 9 '06 #4
I guess I really shouldn't use the term namespace, I suppose what I
meant was reserved names, or things PHP has already used so it doesn't
want you to use them.

So, I'm still having the issues I described and my error level is set
to E_ALL as well according to my php.ini file.

I'll look more into my error reporting setup, but for now, using
language constructs in objects causes my setup to fail silently with
errors set to E_ALL, but it's nice to know that PHP will catch these
errors if setup correctly and that objects can have methods whose names
are the same as global function names.

Apr 9 '06 #5

Nate wrote:
I guess I really shouldn't use the term namespace, I suppose what I
meant was reserved names, or things PHP has already used so it doesn't
want you to use them.

So, I'm still having the issues I described and my error level is set
to E_ALL as well according to my php.ini file.

I'll look more into my error reporting setup, but for now, using
language constructs in objects causes my setup to fail silently with
errors set to E_ALL, but it's nice to know that PHP will catch these
errors if setup correctly and that objects can have methods whose names
are the same as global function names.


I'm afriad you'll need to provide the actual code that causes the
problem, as well as the precise version number of PHP.

Using a reserved keyword would cause PHP to fail at the parsing stage,
so the scenario you described shouldn't happen. Also, names of global
functions are available as method names of a class.

Apr 10 '06 #6
On 9 Apr 2006 15:19:40 -0700, "Nate" <n8*****@gmail.com> wrote:
So, I'm still having the issues I described and my error level is set
to E_ALL as well according to my php.ini file.


The error reporting can overridden by a error_reporting() call. You
might want to make sure you don't have one of those (or alternatively
put one in and set it to E_ALL).

You definately have something wrong with your error reporting.

Apr 10 '06 #7

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

Similar topics

1
by: oj | last post by:
Could someone explain to me why the following code snippet throws an "Object Reference not set to an instance of an object error": public void SetActiveStaffMember(int staffMemberId) { ...
5
by: Ram | last post by:
Hi Friends I want to develope a custom control in .net which can be used with any project. I am writing a function in that class which I want to take any object as parameter. For that I have...
2
by: Aryan | last post by:
Hi, I am implementing Business object, but while implementing this I want to have DataTable or DataSet as part of Business Object. For example, I want to bind controls directly to these Business...
3
by: mak2045 | last post by:
I copied a form (Microsoft 2000 with Visual Basic 6.0) that had a procedure behind the text box and renamed it. I did not get an error message, but the new form that I thought I created did not...
5
by: mikie | last post by:
somebody asked me a question: string is derived from object class, right? (i said yes) so how it could be object class declares method returning string? thanks for any explanation / link /...
8
by: iavian | last post by:
<?php interface Pizza { public function getPrice(); } class Margherita implements Pizza { private $cost = 4.50;
30
by: Logos | last post by:
I have what may be a bug, or may be a misunderstanding on how pass by reference and class inheritance works in PHP. Since I'm relatively new to PHP, I'm hoping for a little outside help to shed...
1
by: ced69 | last post by:
having trouble getting marquee to work get object required errors tring t <title>This Month at the Chamberlain Civic Center</title> <link href="styles.css" rel="stylesheet"...
4
by: pjerald | last post by:
Clear me friends. Object class is the base class for all classes. Thus the methods with protected access in the object class can be invoked by any object(Of any class). I know the statement is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.