473,395 Members | 1,797 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,395 software developers and data experts.

session_start and __autoload()

Hi all.
I just don't understand the behaviour of this: i have a few-webpages
application in which I have these two files (and all the others)

classes/class.User.php
include/stdinclude.php

the code of stdinclude.php is the following:

<CODE>
....
session_start();

function __autoload( $classname ) {
require_once "../classes/class.$class_name.php";
}
....
</CODE>

I was getting the require_once-fatal-error becouse the script couldn't
find "../classes/class.User.php", and I tried to understand where the
include path pointed to: so i dumped the stacktrace and that's what
was in:

(please read the first entry even if it's long)
<BACKTRACE>
[0]=>
array(2) {
["function"]=>
string(10) "__autoload"
["args"]=>
array(1) {
[0]=>
&string(4) "User"
}
}
[1]=>
array(4) {
["file"]=>
string(72) "C:\foo\include\stdinclude.php"
["line"]=>
int(3)
["function"]=>
string(13) "session_start"
["args"]=>
array(0) {
}
}
[2]=>
array(4) {
["file"]=>
string(68) "C:\foo\include\header.php"
["line"]=>
int(3)
["args"]=>
array(1) {
[0]=>
string(72) "C:\foo\include\stdinclude.php"
}
["function"]=>
string(12) "require_once"
}
[3]=>
array(4) {
["file"]=>
string(59) "C:\foo\index.php"
["line"]=>
int(1)
["args"]=>
array(1) {
[0]=>
string(68) "C:\foo\include\header.php"
}
["function"]=>
string(7) "include"
}
}
</BACKTRACE>

in the $_SESSION variable i have an object of type User, and the
session_start() call tries to load the class User by means of
__autoload function, but it is located in nowhere, so i cannot use any
relative path in the require_once ..

this never happends to me before; is this a correct php behaviour ?
should I fix with an absolute path ?

tnx, bye
M

Mar 8 '07 #1
3 2887
Giacomo wrote:
Hi all.
I just don't understand the behaviour of this: i have a few-webpages
application in which I have these two files (and all the others)

classes/class.User.php
include/stdinclude.php

the code of stdinclude.php is the following:

<CODE>
...
session_start();

function __autoload( $classname ) {
require_once "../classes/class.$class_name.php";
}
...
</CODE>

I was getting the require_once-fatal-error becouse the script couldn't
find "../classes/class.User.php", and I tried to understand where the
include path pointed to: so i dumped the stacktrace and that's what
was in:

this never happends to me before; is this a correct php behaviour ?
should I fix with an absolute path ?

tnx, bye
M
Try using dirname(__FILE__).
So: require_once dirname(__FILE__)."/../classes/class.$class_name.php";

Hendri
Mar 8 '07 #2
On Mar 8, 4:46 am, Hendri Kurniawan <ask...@email.comwrote:
Giacomo wrote:
Hi all.
I just don't understand the behaviour of this: i have a few-webpages
application in which I have these two files (and all the others)
classes/class.User.php
include/stdinclude.php
the code of stdinclude.php is the following:
<CODE>
...
session_start();
function __autoload( $classname ) {
require_once "../classes/class.$class_name.php";
}
...
</CODE>
I was getting the require_once-fatal-error becouse the script couldn't
find "../classes/class.User.php", and I tried to understand where the
include path pointed to: so i dumped the stacktrace and that's what
was in:
this never happends to me before; is this a correct php behaviour ?
should I fix with an absolute path ?
tnx, bye
M

Try using dirname(__FILE__).
So: require_once dirname(__FILE__)."/../classes/class.$class_name.php";

Hendri
Dear Giacomo,

the path for require_once() is relative to the initial file, e.g.

1) dummy.php -include('include/stdinclude.php');
2) include/stdinclude.php -require_once('classes/
class.User.php'); // path is relative to dummy
3) classes/class.User.php

I hope that helped
Martin
------------------------------------------------
online accounting on bash bases
Online Einnahmen-Ausgaben-Rechnung
http://www.ea-geier.at
------------------------------------------------
m2m server software gmbh
http://www.m2m.at

Mar 8 '07 #3
On 8 Mar, 10:21, "Martin Mandl - m2m tech support"
<martin.ma...@gmail.comwrote:
On Mar 8, 4:46 am, Hendri Kurniawan <ask...@email.comwrote:
Giacomo wrote:
Hi all.
I just don't understand the behaviour of this: i have a few-webpages
application in which I have these two files (and all the others)
classes/class.User.php
include/stdinclude.php
the code of stdinclude.php is the following:
<CODE>
...
session_start();
function __autoload( $classname ) {
require_once "../classes/class.$class_name.php";
}
...
</CODE>
I was getting the require_once-fatal-error becouse the script couldn't
find "../classes/class.User.php", and I tried to understand where the
include path pointed to: so i dumped the stacktrace and that's what
was in:
this never happends to me before; is this a correct php behaviour ?
should I fix with an absolute path ?
tnx, bye
M
Try using dirname(__FILE__).
So: require_once dirname(__FILE__)."/../classes/class.$class_name.php";
Hendri

Dear Giacomo,

the path for require_once() is relative to the initial file, e.g.

1) dummy.php -include('include/stdinclude.php');
2) include/stdinclude.php -require_once('classes/
class.User.php'); // path is relative to dummy
3) classes/class.User.php

I hope that helped
Martin
Thanks everybody.. i was confused by the fact the if i do this it
works:

1) dummy.php -include('include/stdinclude.php');
2) include/stdinclude.php - require_once('bar.php');
3) include/bar.php

... and of course by the fact that it was 2.00 am o'clock ;)

thanks
bye
M'

Mar 8 '07 #4

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

Similar topics

14
by: Berislav Lopac | last post by:
With the advent of PHP5, with its OO support and the new __autoload function, I was thinking of implementing some king of scheme to organize classes in such a way that they can be easily found by...
5
by: Niklas Uhlin | last post by:
Someone please explain why Session_Start fires multiple times / retains SessionID values between sessions, when you open an ASP.NET page from MS Word. For details of the problem, see below: 1....
4
by: Kevin Newman | last post by:
The primary problem I've had with php is the lack of namespaces, which makes OOP very difficult to organize, since you end up with large number of classes cluttering up the same namespace - which...
19
by: lawrence k | last post by:
How can I find out where my script is outputting to the screen for the first time? My error logs are full of stuff like this: PHP Warning: session_start(): Cannot send session cache...
5
by: paladin.rithe | last post by:
I'm running into an issue with session_start(). I see that you can't run it twice, otherwise it causes an issue. That's fine, and makes sense. I also saw some ideas on how to get around this if...
3
by: mrosado | last post by:
Hi everybody, I have this problem.- The browser launch this two errors: Warning: session_start() : Cannot send session cache limiter - headers already sent (output started at...
1
by: turnitup | last post by:
I am rewriting an application to take advantage of the __autoload functionality. If I accidentally declare a variable in the parent class which was previously declared in a child class, the child...
3
realin
by: realin | last post by:
hiya guys its been long since i posted here .. well i am using pattemplate which is a template tool for website development. But in my website's structure i have placed all my classes into a...
2
by: Ixiaus | last post by:
I was curious (and have spent an enormous amount of time on Google trying to answer it for myself) if Python has anything remotely similar to PHP's SPL __autoload() for loading classes on the fly??...
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:
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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...
0
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,...
0
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...
0
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,...

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.