No content after calling(?) a PHP Class

Hello,

I have created a very simple php page (index.php) to test why I am getting no output after I “call” a php class. I am using an autoloader with the following code, and doing an echo just so I know I get something back. I am loading the autoloader with a bootstrap file which is loaded via php.ini.

spl_autoload_register(‘autoloader’);
function autoloader($class)
{
$path = DIRECTORY_SEPARATOR . ‘class’ . DIRECTORY_SEPARATOR . $class . DIRECTORY_SEPARATOR . $class . ‘.php’;
if(!empty($class)){
echo DIR . $path;
echo $path ;
include $path;
}

I get output from the echos so this is working. In my class file, test.php, I have this code…

Class test
{
public function test(){
echo ‘this is working’;
}
}

In my page index.php I see all echo’d output up to here, but after ‘this is working’ I cannot get anything else. Here is my index.php page I am using for this test.

<!DOCTYPE html>

<?php

$class = new test();

echo 'This is a test, but I cannot see it when I browse the page.';

?>

<html>
<body>

<a href="../../../">To Home!</a> <br />  <!-- Cannot see this either -->

</body>
</html>

Here is a screen shot of the page…

image

I am sure I am missing something, but I cannot find out what. Any help is much appreciated!!!

Thank you,

Leavii

Forgot to mention why I did the calling(?). I am not sure what it is called when you:

$class = class_name();

in php. So I just used calling as a term. Silly I know.

What does the ‘view source’ of the output show in your browser?

Do you have php’s error related settings set to report and display or log all errors? I suspect you are getting a fatal runtime error.

Thank you for the reply. Here is what the view-source page shows.

As far as my error logs I found I didn’t grant the server access to the log directory but I get the following error now.

[27-Mar-2019 17:02:51 UTC] PHP Fatal error:  Cannot break/continue 1 level in C:\inetpub\test\wwwroot\src\wexp\class\test\test.php on line 7

So I went to this file, which is not the correct file for this test it was another so apparently I have an issue in my autoloader, and the directory it is pulling from. But I now get the correct output after checking my error_log file.

Just went, and fixed the autoloader to pull from the correct directory.

Thank you phdr for your reply! I should have guessed that I had something wrong with my error_log permissions when I wasn’t getting errors!

Sponsor our Newsletter | Privacy Policy | Terms of Service