Surya Infotech

PHP variable variables

I want to store courseworks marks of n courseworks into n variables, such as cw1 and cw2 etc. Using variable variables how can I come with cw1, cw2 etc.

How can I dynamically create variables?

Posted by Surya Infotech in php, 0 comments

Understanding PHP Functions

I am beginner in programmer, can anyone describe to me how php function work? I have searched any tutorial but I am still confusing..

Why this function doesn’t work?

<?php
$name = "Maria";
$gender = "Female";
$country = "Thailand";

function profile(){
   echo $name . "<br>";
   echo $gender . "<br>";
   echo $country . "<br>";
}
profile()
?>

Or like this:

<?php
function data(){
   $name = "Maria";
   $gender = "Female";
   $country = "Thailand";
}
function profile(){
   echo $name . "<br>";
   echo $gender . "<br>";
   echo $country . "<br>";
}
data();
profile()
?>
Posted by Surya Infotech in php, 0 comments

What kind of array does PHP use?

I can define an array in PHP like this:

$array = array();

In C++, we have two kinds of array.

  1. The first kind is a fixed size array, for example:
    int arr[4]; // 4 ints, hardcoded size
    
  2. The second kind is a dynamic sized array
    std::vector<int> v; // can grow and shrink at runtime
    

What kind of array does PHP use? Are both kinds of arrays in PHP? If so, can you give me examples?

Posted by Surya Infotech in php, 0 comments

Error handling in PHP

I’m familiar with some of the basics, but what I would like to know more about is when and why error handling (including throwing exceptions) should be used in PHP, especially on a live site or web app. Is it something that can be overused and if so, what does overuse look like? Are there cases where it shouldn’t be used? Also, what are some of the common security concerns in regard to error handling?

Posted by Surya Infotech in php, 0 comments

How do I get PHP errors to display?

I have checked my PHP ini file (php.ini) and display_errors is set and also error reporting is E_ALL. I have restarted my Apache webserver.

I have even put these lines at the top of my script, and it doesn’t even catch simple parse errors. For example, I declare variables with a "$" and I don’t close statements";". But all my scripts show a blank page on these errors, but I want to actually see the errors in my browser output.

error_reporting(E_ALL);
ini_set('display_errors', 1);
Posted by Surya Infotech in php, 0 comments